I\'m using python and I would like to use nested cross-validation with scikit learn. I have found a very good example:
NUM_TRIALS = 30
non_nested_scores = np
You cannot access individual params and best params from cross_val_score
. What cross_val_score
does internally is clone the supplied estimator and then call fit
and score
methods on it with given X
, y
on individual estimators.
If you want to access the params at each split you can use:
#put below code inside your NUM_TRIALS for loop
cv_iter = 0
temp_nested_scores_train = np.zeros(4)
temp_nested_scores_test = np.zeros(4)
for train, test in outer_cv.split(X_iris):
clf.fit(X_iris[train], y_iris[train])
temp_nested_scores_train[cv_iter] = clf.best_score_
temp_nested_scores_test[cv_iter] = clf.score(X_iris[test], y_iris[test])
#You can access grid search's params here
nested_scores_train[i] = temp_nested_scores_train.mean()
nested_scores_test[i] = temp_nested_scores_test.mean()