Three Columns That Count

Machine Learning in CodeMedium+10 XP+10

Three Columns That Count

A scaled logistic regression classifies the three wine growers. Which columns does it actually lean on, measured on wines it has not seen?

Task: write top_columns(n).

  • Load load_wine(return_X_y=True, as_frame=True).
  • Split with train_test_split(X, y, test_size=0.3, random_state=1, stratify=y).
  • Fit make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) on the training rows.
  • Run permutation_importance(model, X_test, y_test, n_repeats=10, random_state=0).
  • Return the names of the n columns with the highest mean importance, highest first.

Examples

n = 1
returns ['alcohol']
n = 3
returns ['alcohol', 'proline', 'ash']

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