The Strongest Columns, One by One

Machine Learning in CodeEasy+10 XP+10

The Strongest Columns, One by One

A clinic wants a shorter test. You score each of the thirty columns on its own against the diagnosis and keep the strongest few.

Task: write kbest_columns(k).

  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 SelectKBest(f_classif, k=k) on the training rows.

Return the names of the kept columns as a list, in the order they appear in the data.

Examples

k = 5
returns ['mean perimeter', 'mean concave points', 'worst radius', 'worst perimeter', 'worst concave points']
k = 2
returns ['mean concave points', 'worst concave points']

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