Final model selection protocol
Quick answer
Final model selection turns a search into a reproducible decision: freeze the metric, folds, candidate budget and tie rule; choose using development scores; refit the selected configuration; evaluate once on a separate test set. Log failures and report uncertainty rather than declaring the winner universally best. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Select only valid trials
trials=[("a",None),("b",82),("c",82),("d",80)]valid=[(k,v) for k,v in trials if v is not None]print(max(valid,key=lambda t:t[1])[0])Observed local output:
bPython max retains the first item in a tie; failed trial a is excluded.
How it works
Begin by specifying the prediction unit, split design and metric direction. For classification accuracy, larger is better; scikit-learn negative-loss scorers also use larger-is-better conventions. Use the same folds and estimator pipeline for a fair comparison, and record the full cv_results_ candidate table. A prespecified tie rule might choose the first candidate in a fixed order, or the simpler candidate within a predefined tolerance. Exclude configurations with invalid or nonfinite scores. If all trials fail, stop and diagnose rather than select a winner. Fit the selected pipeline on development data, then load the held-out labels and compute the chosen metric and baseline. Nested CV is useful when estimating a whole selection procedure without a separate holdout; inner best scores are not unbiased performance estimates. Log versions, seeds, resource budgets, elapsed time separately from reproducible numerical outputs, selected parameters and limitations. A test set used for redesign becomes development data; a fresh evaluation set is then required.
Refit selected pipeline
from sklearn.base import clonefrom sklearn.pipeline import make_pipelinefrom sklearn.preprocessing import StandardScalerfrom sklearn.tree import DecisionTreeClassifierfrom sklearn.model_selection import GridSearchCVX=[[0],[1],[2],[3],[4],[5]];y=[0,0,0,1,1,1]p=make_pipeline(StandardScaler(),DecisionTreeClassifier(random_state=7))s=GridSearchCV(p,{"decisiontreeclassifier__max_depth":[1,2]},cv=2,refit=False).fit(X,y)m=clone(p).set_params(**s.best_params_).fit(X,y)print(m.predict([[0],[5]]).tolist(),bool(m[0].mean_[0]==2.5))Observed local output:
[0, 1] TrueRefit uses development rows only; the illustrative probe inputs have no test labels.
Common mistakes
Do not choose the search strategy by its test score, average ranks across incompatible metrics, or compare only best scores without reporting budgets and failure counts. A high score is not a proof of statistical significance.
Practice and next steps
Create a trial table with a failed trial and two tied valid scores. Apply a predeclared tie rule and describe when to load test labels. Complete the knowledge check and staged exercise. Next: Regression, classification and ranking metrics.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Final model selection protocol — knowledge check
Apply final model selection protocol to new scenarios.
Which data chooses the final configuration?
What if every trial fails?
What should happen before test labels are loaded?
What is a defensible tie policy?
Does the highest CV score establish universal superiority?