简体   繁体   English

__init __()得到了意外的关键字参数'n_splits'错误

[英]__init__() got an unexpected keyword argument 'n_splits' ERROR

I was going to try the code in this link : 我打算尝试此链接中的代码:

I am getting error from the line which refers to StratifiedKFold(n_splits=60) . 我从引用StratifiedKFold(n_splits=60)的行中得到错误。 Can anybody tell me how i can solve this error? 谁能告诉我如何解决这个错误?

Here is the Code: 这是代码:

import numpy as np
from scipy import interp
import matplotlib.pyplot as plt
from itertools import cycle

from sklearn import svm, datasets
from sklearn.metrics import roc_curve, auc
from sklearn.cross_validation import StratifiedKFold

iris = datasets.load_iris()
X = iris.data
y = iris.target
X, y = X[y != 2], y
X, y

cv = StratifiedKFold(n_splits=6)
classifier = svm.SVC(kernel='linear', probability=True,
                     random_state=random_state)

mean_tpr = 0.0
mean_fpr = np.linspace(0, 1, 100)

Here is the error: 这是错误:

TypeError                                 Traceback (most recent call last)
<ipython-input-227-2af2773f4987> in <module>()
----> 1 sklearn.cross_validation.StratifiedKFold(n_splits=6)
      2 #cv = StratifiedKFold(n_splits=6,  shuffle=True, random_state=1)
      3 classifier = svm.SVC(kernel='linear', probability=True,
      4                      random_state=random_state)
      5 

TypeError: __init__() got an unexpected keyword argument 'n_splits'

You are not getting any warnings while importing the sklearn.cross-validation module. 导入sklearn.cross-validation模块时,您没有收到任何警告。 This means that your installed version is less than 0.18. 这意味着您安装的版本小于0.18。

If your scikit-learn version is < 0.18 , then change the below lines: (Taken from StratifiedKFold documentation for version 0.17 ) 如果您的scikit-learn版本< 0.18 ,则更改以下几行:(摘自StratifiedKFold文档中的0.17版

#Notice the extra parameter y and change of name for n_splits to n_folds
cv = StratifiedKFold(y, n_folds=6)

#Also note that the cv is called directly in for loop
for train_index, test_index in cv:
   print("TRAIN:", train_index, "TEST:", test_index)
   X_train, X_test = X[train_index], X[test_index]
   y_train, y_test = y[train_index], y[test_index]

If your scikit-learn version is >=0.18 , then only you can use the n_splits parameter for the cv : (Taken from StratifiedKFold current documentation , which is what I think you are referring to) 如果您的scikit-learn版本>=0.18 ,则只有您可以对cv使用n_splits参数:(摘自StratifiedKFold当前文档 ,这是我认为的意思)

#Notice the extra parameter y is removed here
cv = StratifiedKFold(n_splits=6)

#Also note that the cv.split() is called here (opposed to cv in ver 0.17 above)
for train_index, test_index in cv.split(X, y):
   print("TRAIN:", train_index, "TEST:", test_index)
   X_train, X_test = X[train_index], X[test_index]
   y_train, y_test = y[train_index], y[test_index]

Recommendation : 建议

Update your scikit-learn to the latest version 0.18. 将您的scikit-learn更新到最新版本0.18。 Because most documentation you will find by directly searching will be of this version and it will get you confused. 因为您可以通过直接搜索找到的大多数文档都是此版本,这会让您感到困惑。

Edit: 编辑:

I have already answered your similar question here: - Issue with Cross Validation 我已经在这里回答了您的类似问题:- 交叉验证问题

So next time, please mention the version of libraries you use in the question itself, and remember to access their relevant documentation, not the other ones. 因此,下一次,请提及您在问题本身中使用的库的版本,并记住访问它们的相关文档,而不是其他文档。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SKLearn: TypeError: __init__() 得到了一个意外的关键字参数 n_splits - SKLearn: TypeError: __init__() got an unexpected keyword argument n_splits TypeError:__init __()为参数&#39;n_splits&#39;获取了多个值 - TypeError: __init__() got multiple values for argument 'n_splits' “__init __()得到参数&#39;n_splits&#39;的多个值”与sklearn ShuffleSplit的错误 - “__init__() got multiple values for argument 'n_splits'” error with sklearn ShuffleSplit 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 在sklearn中调用cross_validation时出错-“意外的关键字参数&#39;n_splits” - Error in calling cross_validation in sklearn - “unexpected keyword argument 'n_splits” 类型错误:__init__() 得到了一个意外的关键字参数“n_iter” - TypeError: __init__() got an unexpected keyword argument 'n_iter' pyrouge:__init __()获得了意外的关键字参数&#39;n_words&#39; - pyrouge: __init__() got an unexpected keyword argument 'n_words' TypeError: __init__() 得到了一个意外的关键字参数“n_folds” - TypeError: __init__() got an unexpected keyword argument 'n_folds' TypeError:__init __()获得了意外的关键字参数&#39;n_components&#39; - TypeError: __init__() got an unexpected keyword argument 'n_components'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM