I got this error while runing my code in python 2.6.6. And there is no issue while running in Python 3.4.3
usr/lib64/python2.6/site-packages/sklearn/feature_selection/univariate_selection.py:319: UserWarning: Duplicate scores. Result may depend on feature ordering.There are probably duplicate features, or you used a classification score for a regression task.
warn("Duplicate scores. Result may depend on feature ordering."
Traceback (most recent call last):
File "classification.py", line 31, in <module>
main()
File "classification.py", line 15, in main
tm.optimaltrain(conf)
File "/axp/gabm/npscnnct/dev/getThemes/textminer/textminer/classify.py", line 121, in optimaltrain
score = self.cv(X,y,model)
File "/axp/gabm/npscnnct/dev/getThemes/textminer/textminer/classify.py", line 140, in cv
skf = cross_validation.StratifiedKFold(y, n_folds=self.cv_folds, shuffle=True)
TypeError: __init__() got an unexpected keyword argument 'shuffle'
Code:
def cv(self, X, y, model):
y_true = []
y_pred = []
skf = cross_validation.StratifiedKFold(y, n_folds=self.cv_folds, shuffle=True)
for train_index, test_index in skf:
X_train, X_test = X[train_index], X[test_index]
y_train, y_test = y[train_index], y[test_index]
model.fit(X_train, y_train)
y_pred += list(model.predict(X_test))
y_true += list(y_test)
But when I remove the Shuffle=True
from the code its runing fine. Modules I am using are scipy 0.11.0, nltk 2.0.1, sklearn 0.14.1
Please advice. Thanks
Here is the source for your version ( 0.14
) of sklearn
: https://github.com/scikit-learn/scikit-learn/blob/0.14.X/sklearn/cross_validation.py#L391
I've linked to the actual line for the init on StratifiedKFold
- which shows that there is no shuffle
keyword argument.
Upgrade to v 0.15
, which does have shuffle
(as seen here: https://github.com/scikit-learn/scikit-learn/blob/0.15.X/sklearn/cross_validation.py#L399 ).
I'm going to assume that your version of sklearn
on Py3
is 0.15
?
In sklearn 0.14, cross_validation.StratifiedKFold()
has no keyword argument shuffle
. Apparently, it was only added in a later version (0.15 actually).
You can either update sklearn or shuffle the input yourself (eg. with random.shuffle()
) before stratification.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.