Many Small Steps or a Few Big Ones

Machine Learning in CodeMedium+10 XP+10

Many Small Steps or a Few Big Ones

In boosting, learning_rate and n_estimators pull against each other: a small rate needs many trees, a big rate needs few. You want to compare some pairs on the breast cancer data.

Write boosting_pairs(pairs). Each pair is [learning_rate, n_estimators].

  • 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 pair, in order, fit GradientBoostingClassifier(learning_rate=rate, n_estimators=trees, max_depth=2, random_state=0) on the training rows.
  • Score it on the training rows and on the test rows.

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

Examples

pairs = [[0.01, 30], [0.5, 20]]
returns [[0.01, 30, 0.92, 0.895], [0.5, 20, 1.0, 0.944]]
pairs = [[0.05, 100]]
returns [[0.05, 100, 1.0, 0.937]]

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