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
在python 2.6.6中运行代码时,我得到了这个错误。在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
但是当我从代码中移除Shuffle=True时,它的运行良好。我使用的模块是scipy 0.11.0, nltk 2.0.1, sklearn 0.14.1。
Please advice. Thanks
请建议。谢谢
2 个解决方案
#1
2
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
这里是您的sklearn版本(0.14)的源代码:https://github.com/scikit-learn/scikitlearn/blob/0.14.x/sklearn/cross_valides.py #L391。
I've linked to the actual line for the init on StratifiedKFold
- which shows that there is no shuffle
keyword argument.
我已经将init的实际行链接到层fiedkfold上,这表明没有shuffle关键字参数。
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).
升级到v0.15,它确实有洗牌(如图所示:https://github.com/scikit-learn/scikit-learn/sclearn/cross_valides.py #L399)。
I'm going to assume that your version of sklearn
on Py3
is 0.15
?
假设Py3上的sklearn版本是0。15?
#2
2
In sklearn 0.14, cross_validation.StratifiedKFold()
has no keyword argument shuffle
. Apparently, it was only added in a later version (0.15 actually).
在sklearn 0.14中,cross_valid.层fiedkfold()没有关键字参数调整。显然,它只是在后来的版本中添加了(实际上是0.15)。
You can either update sklearn or shuffle the input yourself (eg. with random.shuffle()
) before stratification.
你可以更新sklearn,也可以自己洗牌(如。与random.shuffle分层前())。
#1
2
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
这里是您的sklearn版本(0.14)的源代码:https://github.com/scikit-learn/scikitlearn/blob/0.14.x/sklearn/cross_valides.py #L391。
I've linked to the actual line for the init on StratifiedKFold
- which shows that there is no shuffle
keyword argument.
我已经将init的实际行链接到层fiedkfold上,这表明没有shuffle关键字参数。
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).
升级到v0.15,它确实有洗牌(如图所示:https://github.com/scikit-learn/scikit-learn/sclearn/cross_valides.py #L399)。
I'm going to assume that your version of sklearn
on Py3
is 0.15
?
假设Py3上的sklearn版本是0。15?
#2
2
In sklearn 0.14, cross_validation.StratifiedKFold()
has no keyword argument shuffle
. Apparently, it was only added in a later version (0.15 actually).
在sklearn 0.14中,cross_valid.层fiedkfold()没有关键字参数调整。显然,它只是在后来的版本中添加了(实际上是0.15)。
You can either update sklearn or shuffle the input yourself (eg. with random.shuffle()
) before stratification.
你可以更新sklearn,也可以自己洗牌(如。与random.shuffle分层前())。