以下是代码:
models = []
models.append(('LR', LogisticRegression()))
models.append(('LDA', LinearDiscriminantAnalysis()))
models.append(('KNN', KNeighborsClassifier()))
models.append(('CART', DecisionTreeClassifier()))
models.append(('NB', GaussianNB()))
models.append(('SVM', SVC()))
# evaluate each model in turn
results = []
names = []
for name, model in models:
kfold = cross_validation.KFold(n_splits=10, random_state=seed)
cv_results = cross_validation.cross_val_score(model, X_train, Y_train, cv=kfold, scoring=scoring)
results.append(cv_results)
names.append(name)
msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
print(msg)
哪会产生此错误: 回溯(最近一次调用最后一次):
文件"",第13行,in kfold = cross_validation.KFold(n_splits = 10,random_state = seed)
TypeError: init ()获得了一个意外的关键字参数' n_splits'
答案 0 :(得分:0)
`cross_validation.KFold`
没有关键字n_splits(see documentation)。它使用k
代替。如果您想拥有n_splits
关键字,可以改为使用sklearn.model_selection.KFold
(see here)。