2 added 164 characters in body
source | link

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
 46. Save the model (this would be the best model with best hyperparameters found by GridsearchCV)
 57. 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)

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(X2, Y2) in order to avoid information leaking from hyperparameter tuning step 2 into training step
 4. Save the model (this would be the best model with best hyperparameters found by GridsearchCV)
 5. Load saved model for future data prediction

If it is not the best way, how can I do it?

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)
1
source | link

Nested cross-validation: hyperparameter tuning, training and saving the best model for future data prediction?

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(X2, Y2) in order to avoid information leaking from hyperparameter tuning step 2 into training step
 4. Save the model (this would be the best model with best hyperparameters found by GridsearchCV)
 5. Load saved model for future data prediction

If it is not the best way, how can I do it?