Evidence for the Wine Model

Machine Learning in CodeMedium+10 XP+10

Evidence for the Wine Model

A reviewer wants three things before trusting a wine classifier: how often it is right, how that compares to guessing, and what it leans on.

Task: write wine_evidence(n).

  • Load load_wine(return_X_y=True, as_frame=True) and split with train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).
  • Fit make_pipeline(StandardScaler(), LogisticRegression(max_iter=1000)) on the training rows.
  • Fit DummyClassifier(strategy="most_frequent") on the training rows as the baseline.
  • Run permutation_importance(model, X_test, y_test, n_repeats=10, random_state=0) on the pipeline.
  • Return a dict:
    • "model": the pipeline's test accuracy, rounded to 3 decimal places
    • "baseline": the dummy's test accuracy, rounded to 3 decimal places
    • "leans_on": the names of the n most important columns, highest first

Examples

n = 2
returns {'model': 1.0, 'baseline': 0.4, 'leans_on': ['proline', 'alcohol']}
n = 1
returns {'model': 1.0, 'baseline': 0.4, 'leans_on': ['proline']}

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