The Quiet Column Speaks

Machine Learning in CodeMedium+10 XP+10

The Quiet Column Speaks

Fruit are described by weight (hundreds of grams) and sweetness (a small score). Without scaling, weight drowns out sweetness. See whether scaling changes the answers.

Task: write raw_and_scaled(train_rows, train_labels, new_rows). Each row is [weight, sweetness].

  • Raw: train a KNeighborsClassifier(n_neighbors=1) on the rows as they are, and predict new_rows.
  • Scaled: fit a MinMaxScaler on train_rows only, transform both train_rows and new_rows with it, train a fresh KNeighborsClassifier(n_neighbors=1) on the scaled training rows, and predict the scaled new rows.
  • Return [raw predictions, scaled predictions], each a list in the order of new_rows.

Examples

train_rows = [[150, 2], [158, 9], [120, 3], [128, 8]]
train_labels = ["sour", "sweet", "sour", "sweet"]
new_rows = [[152, 8], [126, 3]]
returns [['sweet', 'sweet'], ['sweet', 'sour']]
train_rows = [[1000, 1], [1030, 5], [900, 2], [940, 4]]
train_labels = ["no", "yes", "no", "yes"]
new_rows = [[1001, 5], [935, 2], [1029, 1]]
returns [['no', 'yes', 'yes'], ['yes', 'no', 'no']]

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