Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Description

@equialgo
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'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions