KNN บนข้อมูลที่ยังไม่ได้ปรับมาตราส่วน
ก่อนจะเพิ่มขั้นตอนการ standardization เข้าไปใน workflow ของ scikit-learn ลองดูความแม่นยำของโมเดล K-nearest neighbors บนชุดข้อมูล wine โดยยังไม่ต้อง standardize ข้อมูลก่อน
โมเดล knn รวมถึงชุดข้อมูล X, y และ labels ได้ถูกสร้างไว้ให้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การเตรียมข้อมูลสำหรับ Machine Learning ด้วย Python
คำแนะนำการฝึกหัด
- แบ่งชุดข้อมูลออกเป็น training set และ test set
- Fit โมเดล
knnกับข้อมูล training - แสดงค่าความแม่นยำของโมเดล
knnบน test set
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# 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(____.____(____, ____))