Reputation: 21
I am trying to execute a for loop for the following dictionary, but I am receiving an error that states:
"cross_val_score() got an unexpected keyword argument 'return_train_score'"
I thought this was a valid parameter for cross_val_score so I'm a bit confused any help would be appreciated,
thanks
results_dict = {
"n_neighbors": [],
"mean_train_score": [],
"mean_cv_score": []}
results_dict
for k in range(2,20, 2):
knn = KNeighborsClassifier(n_neighbors=k)
scores = cross_val_score(knn, X_train, y_train, cv=5, return_train_score=True)
results_dict['n_neighbors'].append(k)
results_dict['mean_train_score'].append(['train_score'])
results_dict['mean_cv_score'].append(['test_score'])
results_dict
Upvotes: 1
Views: 367
Reputation: 67
I believe you want to use the function cross_validate
instead of cross_val_score
.
Upvotes: 1
Reputation: 595
Check documentation of the cross_val_score function here
The cross_val_score doesn't have any such parameter named return_train_score. So, I suggest removing this parameter will eliminate this error.
Upvotes: 2