简体   繁体   English

TypeError:__init __()为参数'n_splits'获取了多个值

[英]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.

相关问题 TypeError:__init__() 为straifiedkfold 的参数“n_splits”获得了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' forstraifiedkfold TypeError:__init__() 在癌症数据集中为参数“n_splits”获得了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' in the cancer dataset “__init __()得到参数&#39;n_splits&#39;的多个值”与sklearn ShuffleSplit的错误 - “__init__() got multiple values for argument 'n_splits'” error with sklearn ShuffleSplit __init __()得到了意外的关键字参数&#39;n_splits&#39;错误 - __init__() got an unexpected keyword argument 'n_splits' ERROR SKLearn: TypeError: __init__() 得到了一个意外的关键字参数 n_splits - SKLearn: TypeError: __init__() got an unexpected keyword argument n_splits Python TypeError:__ init __()为参数&#39;master&#39;获取了多个值 - Python TypeError: __init__() got multiple values for argument 'master' TypeError:__init __()为关键字参数“ choices”获得了多个值 - TypeError: __init__() got multiple values for keyword argument 'choices' TypeError:“ __ init __()为关键字参数&#39;name&#39;获得了多个值” - TypeError: “__init__() got multiple values for keyword argument 'name'” TypeError: __init__() 为参数 'center' 获得了多个值 - TypeError: __init__() got multiple values for argument 'center' TypeError:__ init __()得到关键字参数&#39;customer&#39;的多个值 - TypeError: __init__() got multiple values for keyword argument 'customer'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM