The Column You Forgot

Machine Learning in CodeMedium+10 XP+10

The Column You Forgot

A ColumnTransformer quietly drops any column you don't name, unless you tell it otherwise.

Task: write output_widths(table, scaled_columns).

  • table is a dict mapping column names to lists of numbers. scaled_columns names some of them.
  • Build two ColumnTransformers with one line each: ("numbers", StandardScaler(), scaled_columns).
    • The first uses the default remainder.
    • The second uses remainder="passthrough".
  • Fit and transform the table with each one.
  • Return [columns out of the first, columns out of the second].

Examples

table = {"weight": [150, 170, 130], "sweet": [7, 8, 3], "seeds": [5, 9, 0]}
scaled_columns = ["weight", "sweet"]
returns [2, 3]
table = {"a": [1, 2], "b": [3, 4], "c": [5, 6], "d": [7, 8]}
scaled_columns = ["d"]
returns [1, 4]

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