Is my understanding correct that "greed_search.fit(X,Y)" has nothing with nested CV in the following code? Meaning that there is no way to get the best parameters using nested CV in sklearn.
# inner cross_validation
greed_search = GridSearchCV(estimator=estimator, param_grid=parameters, cv=inner_cv, scoring=optimized_for)
greed_search.fit(X, optimization_label)
# Nested CV with parameter optimization
nested_score = cross_val_score(greed_search, X=X, y=Y, cv=outer_cv)
You are right: the greed_search.fit(X, optimization_label)
in your code is performed as is without being nested into the next cross validation.
To answer your second question I ask you another question: What should be the best parameters of the grid search nested into the cross validation? The ones of the first fold? the most commons?
The inner grid search, at each step of the outer cross validation, selects the best parameters according to the training data of the current step. Hence the parameters can change among the folds. Doing the outer cross validation by yourself you can compute the best parameters of each step, but I don't think you really need it.
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