Scaled डेटा पर KNN
Unscaled wine डेटासेट पर accuracy score ठीक-ठाक था, लेकिन standardization का उपयोग करके आप क्या हासिल कर सकते हैं, यह देखते हैं। एक बार फिर, knn मॉडल के साथ-साथ X और y डेटा और लेबल सेट आपके लिए पहले से बनाए जा चुके हैं।
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Machine Learning के लिए Preprocessing
अभ्यास निर्देश
StandardScaler()मेथड बनाएँ और उसेscalerनाम के वैरिएबल में स्टोर करें.- Training और test फीचरों को scale करें, ध्यान रहे कि data leakage न हो.
- Scaled training डेटा पर
knnमॉडल को fit करें. - Test set accuracy निकालकर मॉडल का प्रदर्शन evaluate करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
X_train, X_test, y_train, y_test = train_test_split(X, y, stratify=y, random_state=42)
# Instantiate a StandardScaler
scaler = ____
# Scale the training and test features
X_train_scaled = ____.____(____)
X_test_scaled = ____.____(____)
# Fit the k-nearest neighbors model to the training data
____.____(____, ____)
# Score the model on the test data
print(____.____(____, ____))