0
votes

Here is the code:

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)

Which produces this error: Traceback (most recent call last):

File "", line 13, in kfold = cross_validation.KFold(n_splits=10, random_state=seed)

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

1

1 Answers

0
votes
`cross_validation.KFold` 

does not have keyword n_splits (see documentation). It uses k instead. If you want to have n_splits keyword, you may use sklearn.model_selection.KFold instead (see here).