Atelier : kNN contre arbre
Échelle, k et profondeur sur CV.
Énoncé
Sur tabulaire hétérogène : kNN avec échelle vs arbre, k et max_depth sur CV, verdict test avec matrice. Testez l'ajout de 5 colonnes bruit pour illustrer la malédiction.
Contraintes
kNN sans échelle interdit, graines notées, test unique.
Indices
KNeighborsClassifier dans pipeline avec échelle, DecisionTreeClassifier(max_depth=...), bruit rng.normal.
Correction disponibleCherchez d’abord par vous-même.Voir la correction
Correction
knn = make_pipeline(StandardScaler(), KNeighborsClassifier())
tree = DecisionTreeClassifier(random_state=0)
Attendu : kNN chute avec bruit et sans échelle, arbre stable. Moralité : distances = soignez l'espace, arbres = soignez la profondeur.