What the Forest Leaned On

Machine Learning in CodeEasy+10 XP+10

What the Forest Leaned On

A forest counts how much each column improved its splits while it trained. That count is free to read once the forest is fitted.

Task: write top_built_in(n).

  1. Load the data with load_breast_cancer(return_X_y=True, as_frame=True).
  2. Split it with train_test_split(X, y, test_size=0.25, random_state=0, stratify=y).
  3. Fit RandomForestClassifier(n_estimators=100, random_state=0) on the training rows.

Return the names of the n columns with the highest feature_importances_, most important first.

Examples

n = 3
returns ['worst perimeter', 'worst radius', 'worst concave points']
n = 1
returns ['worst perimeter']

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