未縮放資料上的 KNN
在把標準化加入你的 scikit-learn 工作流程之前,先看看在未標準化資料的情況下,K 近鄰模型在 wine 資料集上的準確率如何。
knn 模型,以及 X 與 y 的資料和標籤集合都已經建立好了。
本練習屬於課程
Python 的 Machine Learning 前處理
練習說明
- 將資料集切分為訓練集與測試集。
- 將
knn模型擬合到訓練資料。 - 列印你所訓練
knn模型在測試集上的準確率。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Split the dataset and labels into training and test sets
X_train, X_test, y_train, y_test = ____(____, ____, stratify=y, random_state=42)
# Fit the k-nearest neighbors model to the training data
____
# Score the model on the test data
print(____.____(____, ____))