未缩放数据上的 KNN
在将标准化加入您的 scikit-learn 工作流之前,先看看在未标准化数据的情况下,K 近邻模型在 wine 数据集上的准确率如何。
knn 模型以及 X 和 y 的数据与标签集合已为您创建好。
本练习是课程的一部分
Python 中的机器学习预处理
练习说明
- 将数据集拆分为训练集和测试集。
- 将
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(____.____(____, ____))