I am trying to fetch mean train score from classifierobject.cv_result_
from GridSearchCV
method using 5 fold cross-validation but it's giving me *** KeyError: 'mean_train_score'
in Google Colab. However, the same code is running fine in local machine Ipython notebook for sklearn
version 0.19.1.
Can anyone help me how can I get the output in google colab?
clf.cv_results_.keys()
ouputs following -
for my local notebook -
dict_keys(['mean_fit_time', 'std_fit_time', 'mean_score_time', 'std_score_time', 'param_n_neighbors', 'params', 'split0_test_score', 'split1_test_score', 'split2_test_score', 'split3_test_score', 'split4_test_score', 'mean_test_score', 'std_test_score', 'rank_test_score', 'split0_train_score', 'split1_train_score', 'split2_train_score', 'split3_train_score', 'split4_train_score', 'mean_train_score', 'std_train_score'])
on google colab notebook -
dict_keys(['mean_fit_time', 'std_fit_time', 'mean_score_time', 'std_score_time', 'param_n_neighbors', 'params', 'split0_test_score', 'split1_test_score', 'split2_test_score', 'split3_test_score', 'split4_test_score', 'mean_test_score', 'std_test_score', 'rank_test_score'])
where is the mean_train_score
in google colab. Am I missing something?
from sklearn.model_selection import GridSearchCV
neigh = KNeighborsClassifier(n_jobs=-1)
parameters = {'n_neighbors':[1, 5, 10, 15, 19 , 21, 31, 41, 51]}
clf = GridSearchCV(neigh, parameters, cv=5,\
scoring='roc_auc',n_jobs=-1)
clf.fit(x_train, y_train)
train_auc= clf.cv_results_['mean_train_score']
train_auc_std= clf.cv_results_['std_train_score']
cv_auc = clf.cv_results_['mean_test_score']
cv_auc_std= clf.cv_results_['std_test_score']
Try setting return_train_score=True
inside GridSearchCV()
to calculate the train scores (are off by default, see docs). Maybe you have kind of global variable in sklearn
somewhere local set.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With