ageron / ageron/handson-ml2

[Chapter 3] Why does scaling the inputs improve the performance of the SGD classifier but not the kNN classifier?

オープン
#177 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Jupyter Notebook
スター
30k
フォーク
13.1k
PR マージ指標
30日以内にマージされた PR はありません

説明

Hi, so in Chapter 3 the StandardScaler transformer is used on the training set to improve the performance of the SGDClassifier, boosting the accuracy by 4-5%.

For Exercise 1, I decided to use this transformer for the kNN classifier to see if I could boost the performance past the 97% accuracy given in the solution. Here is the code I used:

`from sklearn.model_selection import GridSearchCV`

`knn_clf_ex = KNeighborsClassifier()`

`param_grid = [`
`{'weights':['uniform','distance'],'n_neighbors':[4,5,6]}`
]

`grid_search = GridSearchCV(knn_clf_ex, param_grid, cv=3,scoring='accuracy',`
` return_train_score=False,verbose=3)`
`grid_search.fit(X_train_scaled,y_train)`
`grid_search.best_params_`

`knn_model = grid_search.best_estimator_`
`X_test_prepared = scaler.transform(X_test.astype(np.float64))`

`from sklearn.metrics import accuracy_score`

`y_test_pred = knn_model.predict(X_test_prepared)`
`accuracy_score(y_test, y_test_pred)`

After 6 hours of runtime, this yielded an accuracy of only 95%. Why is this the case? From searching online it seems highly recommended to scale the inputs to the kNN algorithm. I can't think of any reason for the decreased performance. Any help or explanation is appreciated, thanks.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。