[英]TypeError: __init__() got multiple values for argument 'n_splits'
I'm using SKLearn version (0.20.2) following by: 我正在使用以下版本的SKLearn版本(0.20.2):
from sklearn.model_selection import StratifiedKFold
grid = GridSearchCV(
pipeline, # pipeline from above
params, # parameters to tune via cross validation
refit=True, # fit using all available data at the end, on the best found param combination
scoring='accuracy', # what score are we optimizing?
cv=StratifiedKFold(label_train, n_splits=5), # what type of cross validation to use
)
But i don't understand why i will get this error: 但是我不明白为什么我会得到这个错误:
TypeError Traceback (most recent call last)
<ipython-input-26-03a56044cb82> in <module>()
10 refit=True, # fit using all available data at the end, on the best found param combination
11 scoring='accuracy', # what score are we optimizing?
---> 12 cv=StratifiedKFold(label_train, n_splits=5), # what type of cross validation to use
13 )
TypeError: __init__() got multiple values for argument 'n_splits'
Im already tried n_fold
but come with the same error result. 我已经尝试过
n_fold
但结果相同。 And also tired to update my scikit version and my conda. 并且也厌倦了更新我的scikit版本和我的conda。 Any idea to fix this ?
有解决这个问题的主意吗? Thanks a lot!
非常感谢!
StratifiedKFold takes exactly 3 arguments when initialized, none of which are the training data: 初始化时StratifiedKFold恰好接受3个参数,都不是训练数据:
StratifiedKFold(n_splits='warn', shuffle=False, random_state=None)
So when you call StratifiedKFold(label_train, n_splits=5)
it thinks you passed n_splits
twice. 因此,当您调用
StratifiedKFold(label_train, n_splits=5)
它会认为您两次传递了n_splits
。
Instead, create the object, then use the methods as described in the example on the sklearn docs page for using the object to split your data: 而是创建对象,然后使用sklearn docs页面上的示例中所述的方法使用对象拆分数据:
get_n_splits([X, y, groups]) Returns the number of splitting iterations in the cross-validator split(X, y[, groups]) Generate indices to split data into training and test set.
get_n_splits([X,y,groups])返回交叉验证程序中的分割迭代次数split(X,y [,groups])生成索引以将数据分割为训练和测试集。
StratifiedKFold takes three arguments but you are passing two arguments. StratifiedKFold接受三个参数,但是您要传递两个参数。 See more in sklearn documentation
在sklearn 文档中查看更多
Create StratifiedKFold object and pass it to GridSearchCV as below. 创建StratifiedKFold对象,并将其传递给GridSearchCV,如下所示。
skf = StratifiedKFold(n_splits=5)
skf.get_n_splits(X_train, Y_train)
grid = GridSearchCV(
pipeline, # pipeline from above
params, # parameters to tune via cross validation
refit=True, # fit using all available data at the end, on the best found param combination
scoring='accuracy', # what score are we optimizing?
cv=skf, # what type of cross validation to use
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.