3.1. Exercises

Name that Scaling Method!

Scaling True or False

Practicing Scaling

Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.

When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.

Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line won’t execute and you can test your code after each step.

Now that we have a basketball dataset that no longer is missing any values, let’s scale the features.

First, let’s scale using standardization.

Tasks:

  • Build the transformer and name it ss_scaler.
  • Fit and transform the data X_train and save the transformed feature vectors in objects named X_train_scaled.
  • Transform X_test and save it in an object named X_test_scaled.
  • Build a KNN classifier and name it knn.
  • Fit your model on the newly scaled training data.
  • Save the training score to 3 decimal places in an object named ss_score.
Hint 1
  • Are you using ss_scaler.fit_transform(X_train)?
  • Are you using ss_scaler.transform(X_test)?
  • Are you using KNeighborsClassifier() to create your model?
  • Are you using knn.fit(X_train_scaled, y_train) to train your data?
  • To obtain the training score are you using round(knn.score(X_train_scaled, y_train), 3)?
Fully worked solution: