One Object, Scaled First

Machine Learning in CodeEasy+10 XP+10

One Object, Scaled First

The wine data has columns on wildly different scales. A pipeline puts a scaler in front of the model so you can't forget it.

Task: write pipeline_score(scaler_name, k).

  • scaler_name is "standard" (use StandardScaler) or "minmax" (use MinMaxScaler).
  • Load the wine data as X and y, and split with train_test_split(X, y, test_size=0.25, random_state=0).
  • Build a pipeline of that scaler followed by KNeighborsClassifier(n_neighbors=k), and fit it on the training rows.
  • Return the pipeline's test score, rounded to 3 decimal places.

Examples

scaler_name = "standard"
k = 5
returns 0.978
scaler_name = "minmax"
k = 3
returns 0.978

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run