Look Inside

Machine Learning in CodeMedium+10 XP+10

Look Inside

A fitted pipeline isn't a black box. Each step is still there, carrying what it learned.

Task: write inspect_pipeline(train_rows, train_labels).

  • train_rows is a list of rows of numbers, and train_labels the answers. There are at least 3 rows.
  • Build make_pipeline(StandardScaler(), KNeighborsClassifier(n_neighbors=3)) and fit it on the rows.
  • Return a dict:
    • "steps": the names of the pipeline's steps, in order, as a list of strings.
    • "means": the column averages the scaler learned, as a list, each rounded to 2 decimal places.

Examples

train_rows = [[150, 7], [170, 8], [130, 3], [110, 2], [160, 6]]
train_labels = ["apple", "apple", "lemon", "lemon", "apple"]
returns {'steps': ['standardscaler', 'kneighborsclassifier'], 'means': [144.0, 5.2]}
train_rows = [[1, 10, 100], [2, 20, 300], [4, 30, 200]]
train_labels = [0, 1, 1]
returns {'steps': ['standardscaler', 'kneighborsclassifier'], 'means': [2.33, 20.0, 200.0]}

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