The Loud Column

Machine Learning in CodeMedium+10 XP+10

The Loud Column

A fruit stall describes each fruit by [weight in grams, sweetness from 1 to 10] and labels it "sour" or "sweet". Weight is written in much bigger numbers than sweetness, so without scaling it drowns sweetness out.

Write bare_and_scaled(rows, labels, new_row, k).

  • Bare: fit KNeighborsClassifier(n_neighbors=k) on the rows as they are.
  • Scaled: fit make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=k)) on the same rows.
  • Ask both for the label of the single fruit new_row.

Return a dict {"bare": ..., "scaled": ...} holding the two predicted labels as strings.

Examples

rows = [[140, 2.0], [142, 2.5], [144, 3.0], [100, 8.0], [180, 8.2], [190, 7.8]]
labels = ['sour', 'sour', 'sour', 'sweet', 'sweet', 'sweet']
new_row = [143, 7.9]
k = 3
returns {'bare': 'sour', 'scaled': 'sweet'}
rows = [[140, 2.0], [142, 2.5], [144, 3.0], [100, 8.0], [180, 8.2], [190, 7.8]]
labels = ['sour', 'sour', 'sour', 'sweet', 'sweet', 'sweet']
new_row = [141, 2.2]
k = 3
returns {'bare': 'sour', 'scaled': 'sour'}

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