Choosing among many models without being fooled by luck
For models whose prediction is a weighted sum of the training labels: add up the weight each point gives to its own label.
\(n\): training points · \(p\): columns · \(k\): neighbors in k-nearest neighbors (k-NN) · \(\alpha\): the Ridge penalty.
| model | effective parameters | with \(n = 30\) |
|---|---|---|
| least squares, \(p\) columns | \(p\) | |
| k-NN | \(n / k\) | \(k = 30\): 1 · \(k = 3\): 10 · \(k = 1\): 30 |
| Ridge | falls from \(p\) toward 1 (the unpenalized intercept) as \(\alpha\) grows | continuous |
Degree, \(k\) and \(\alpha\) on the same 30-point sample, on the effective-parameters axis. Predict. Do the three bottoms fall close together?
Score = ability (standard deviation, sd, 8) + luck of the day (its sd in the first column). Reliability: \(r = \frac{\sigma^2_\text{ability}}{\sigma^2_\text{ability} + \sigma^2_\text{luck}} = \frac{8^2}{8^2 + \text{luck}^2}\).
Predict. The top 10% on exam 1: do they keep their score on exam 2? And when luck grows?
| luck sd | \(r\) | exam 1 | exam 2 |
|---|---|---|---|
| 2 | 0.94 | 84.4 | 83.5 |
| 6 | 0.64 | 87.6 | 80.9 |
| 16 | 0.20 | 101.4 | 76.1 |
The top 10% come back to \(70 + r \cdot D\). Predict. With \(\sigma = 0\), how far do they fall? And with \(\sigma = 16\)?
pipe = Pipeline([('scale', StandardScaler()), ('model', LogisticRegression())])
param_grid = [ # a list of grids: one per family
{'model': [LogisticRegression(max_iter=5000)], 'model__C': np.logspace(-3, 3, 7)},
{'model': [KNeighborsClassifier()], 'model__n_neighbors': [1, 3, 5, 9, 15, 25, 51]},
{'model': [SVC()], 'model__C': [0.1, 1, 10, 100], 'model__gamma': ['scale', 0.01, 0.1]},
{'model': [DecisionTreeClassifier(random_state=0)], 'scale': ['passthrough'],
'model__max_depth': [1, 2, 3, 4, 6, 8, 12, None]},
{'model': [RandomForestClassifier(n_estimators=200, random_state=0)], 'scale': ['passthrough'],
'model__max_features': ['sqrt', 0.5], 'model__min_samples_leaf': [1, 5]},
{'model': [HistGradientBoostingClassifier(random_state=0)], 'scale': ['passthrough'],
'model__learning_rate': [0.05, 0.1], 'model__max_leaf_nodes': [7, 31]},
]
Radar returns: 42 configurations, 6 families, one search. Support vector machine (SVM) 0.946 · forest 0.943 · boosting 0.940 (a three-way tie) · tree 0.897 · logistic 0.883 · k-NN 0.866.
model slot takes different estimators; 'passthrough' switches a step off. The same cv for all of them: they can be compared fold by fold.| dataset | logistic | k-NN | SVM | tree | forest | boosting |
|---|---|---|---|---|---|---|
| ionosphere (real) | 0.883 | 0.866 | 0.946 | 0.897 | 0.943 | 0.940 |
| breast cancer (real) | 0.979 | 0.965 | 0.979 | 0.930 | 0.967 | 0.972 |
| credit-g (real) | 0.761 | 0.735 | 0.760 | 0.719 | 0.764 | 0.771 |
| linear, 40-d | 0.820 | 0.710 | 0.805 | 0.725 | 0.735 | 0.720 |
| two moons | 0.853 | 0.900 | 0.895 | 0.887 | 0.893 | 0.895 |
| axis-aligned rule | 0.640 | 0.636 | 0.686 | 0.938 | 0.948 | 0.944 |
the boundary is a hyperplane
nearby points share labels
the boundary is smooth
a few thresholds on a few features; the forest averages away the variance of that bet, boosting the bias
Framed = within 1 fold sd of the winner. Predict. On how many datasets are the trees (forest or boosting) on top or tied with it?
The same word, three ideas of this lesson.
| what it means | what to do | |
|---|---|---|
| bias (bias–variance) | a family's systematic error, on average over training sets | more capacity, better features |
| inductive bias | a family's bet on the shape of the problem | pick the family whose bet matches |
| selection bias | the winner of a search has an optimistic score | measure again on data that did not choose |
42 configurations of similar accuracy, noisy scores. Predict. Is the winner's validation score above, below or equal to its true accuracy? And if you pick by the test?
pre, cv, rmse and candidates from steps 1 to 6.Pace: step 7 and the first simulation in 12 min; step 8 in 8 min; step 9 and the second simulation in 10 min.