Rein It In

Machine Learning in CodeMedium+10 XP+10

Rein It In

A fully grown tree builds branches for single rows. min_samples_leaf stops that: every leaf must hold at least that many training rows.

Write leaf_size_scores(leaf_sizes) for the breast cancer data.

  • Load the data with load_breast_cancer(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).
  • For each value in leaf_sizes, in order, fit DecisionTreeClassifier(min_samples_leaf=value, random_state=0) on the training rows.
  • Score it on the training rows and on the test rows.

Return a list with one [value, train_score, test_score] per value, with both scores rounded to 3 places.

Examples

leaf_sizes = [1, 5]
returns [[1, 1.0, 0.902], [5, 0.977, 0.923]]
leaf_sizes = [10]
returns [[10, 0.955, 0.916]]

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