BaşlayınÜcretsiz Başlayın

KNN on scaled data

The accuracy score on the unscaled wine dataset was decent, but let's see what you can achieve by using standardization. Once again, the knn model as well as the X and y data and labels set have already been created for you.

Bu egzersiz

Preprocessing for Machine Learning in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create the StandardScaler() method, stored in a variable named scaler.
  • Scale the training and test features, being careful not to introduce data leakage.
  • Fit the knn model to the scaled training data.
  • Evaluate the model's performance by computing the test set accuracy.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

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(____.____(____, ____))
Kodu Düzenle ve Çalıştır