8000 Using a Pandas Series/DataFrame with `permutation_test_score` results in error. · Issue #5696 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Using a Pandas Series/DataFrame with permutation_test_score results in error. #5696

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
equialgo opened this issue Nov 2, 2015 · 3 comments
Closed

Comments

@equialgo
Copy link
Contributor
equialgo commented Nov 2, 2015
import pandas as pd
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import permutation_test_score

X = pd.DataFrame(np.random.randint(10, size=(10,5)))
y = pd.Series(np.random.randint(10, size=(10,)))

reg = LinearRegression()

permutation_test_score(reg, X, y)

Results in the following error:


KeyError                                  Traceback (most recent call last)
<ipython-input-5-76791d923d7c> in <module>()
     10 reg = LinearRegression()
     11 
---> 12 permutation_test_score(reg, X, y)

/Users/stijntonk/anaconda/lib/python3.4/site-packages/sklearn/cross_validation.py in permutation_test_score(estimator, X, y, cv, n_permutations, n_jobs, labels, random_state, verbose, scoring)
   1695     # We clone the estimator to make sure that all the folds are
   1696     # independent, and that it is pickle-able.
-> 1697     score = _permutation_test_score(clone(estimator), X, y, cv, scorer)
   1698     permutation_scores = Parallel(n_jobs=n_jobs, verbose=verbose)(
   1699         delayed(_permutation_test_score)(

/Users/stijntonk/anaconda/lib/python3.4/site-packages/sklearn/cross_validation.py in _permutation_test_score(estimator, X, y, cv, scorer)
   1543     avg_score = []
   1544     for train, test in cv:
-> 1545         estimator.fit(X[train], y[train])
   1546         avg_score.append(scorer(estimator, X[test], y[test]))
   1547     return np.mean(avg_score)

/Users/stijntonk/anaconda/lib/python3.4/site-packages/pandas/core/frame.py in __getitem__(self, key)
   1906         if isinstance(key, (Series, np.ndarray, Index, list)):
   1907             # either boolean or fancy integer index
-> 1908             return self._getitem_array(key)
   1909         elif isinstance(key, DataFrame):
   1910             return self._getitem_frame(key)

/Users/stijntonk/anaconda/lib/python3.4/site-packages/pandas/core/frame.py in _getitem_array(self, key)
   1950             return self.take(indexer, axis=0, convert=False)
   1951         else:
-> 1952             indexer = self.ix._convert_to_indexer(key, axis=1)
   1953             return self.take(indexer, axis=1, convert=True)
   1954 

/Users/stijntonk/anaconda/lib/python3.4/site-packages/pandas/core/indexing.py in _convert_to_indexer(self, obj, axis, is_setter)
   1119                 mask = check == -1
   1120                 if mask.any():
-> 1121                     raise KeyError('%s not in index' % objarr[mask])
   1122 
   1123                 return _values_from_object(indexer)

KeyError: '[5 6 7 8 9] not in index'
@raghavrv
Copy link
Member

Fix at #5697

@cmarmo
Copy link
Contributor
cmarmo commented Oct 10, 2019

Hello core-devs,
if I may... this one could probably be closed...
If I understand correctly
from sklearn.cross_validation import permutation_test_score
has been replaced by
from sklearn.model_selection import permutation_test_score
and the code provided above run without errors using master.

@thomasjpfan
Copy link
Member

Thank you @cmarmo. This original issue is fixed and this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants
0