0
$\begingroup$

Is it sensible to do the following:

Given:

Data: X of size n x d
Labels: Y of size n x 1

Goal:

Save the best model after hyperparameter tuning for future data, such that it is nested cross-validated. So, can I do the following:

 1. Split X and Y in two parts: X1, Y1 and X2, Y2
 2. clf = GridserachCV()
 3. clf.fit(X1, Y1)
 4. Get the best_params_ and do GridsearchCV() again with the best parameter found, i.e., redo_clf = GridsearchCV(best_params_,)
 5. redo_clf.fit(X2, Y2) in order to avoid information leaking from hyperparameter tuning step 2 into training step
 6. Save the model (this would be the best model with best hyperparameters found by GridsearchCV)
 7. Load saved model for future data prediction

If it is not the best way, how can I do it? Can you show me how to do step 4 in complete? I think it should be something like this:

GridSearchCV(best_model, best_model_params, cv=inner_cv)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.