What the Forest Leaned On

Machine Learning in CodeMedium+10 XP+10

What the Forest Leaned On

A winery wants to know which chemical measurements matter most for telling its three grape varieties apart.

Write top_wine_features(n).

  • Load the data with load_wine(return_X_y=True, as_frame=True) and split it with train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).
  • Fit RandomForestClassifier(n_estimators=100, random_state=0) on the training rows.
  • Rank the columns by feature_importances_, biggest first.

Return a list of the n most important column names.

Examples

n = 1
returns ['proline']
n = 3
returns ['proline', 'flavanoids', 'color_intensity']

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