A Queue of Small Fixes

Machine Learning in CodeEasy+10 XP+10

A Queue of Small Fixes

Boosting lines up many tiny trees, each one fixing what the ones before it missed. Use it on the garden centre's soil data: each row is [pH, moisture %], labelled 1 if the plant thrived and 0 if it struggled.

Write boosted_predict(rows, thrived, new_rows, trees).

  • Fit GradientBoostingClassifier(n_estimators=trees, max_depth=1, random_state=0). Each tree asks a single question.
  • Predict every row in new_rows, in order.

Return the predictions as a list of ints.

Examples

rows = [[6.5, 42.8], [6.6, 34.6], [6.4, 38.2], [6.2, 32.4], [6.4, 34.8], [6.2, 32.6], [6.5, 39.1], [6.9, 34.9], [6.4, 41.1], [6.3, 40.6], [6.6, 39.3], [6.6, 29.9], [6.5, 37.8], [6.2, 39.8], [6.5, 40.5], [4.5, 15.8], [4.9, 25.4], [4.7, 22.5], [4.8, 19.4], [5.3, 30.0], [4.8, 25.0], [5.0, 17.2], [5.3, 22.3], [4.8, 24.3], [5.0, 21.2], [5.0, 24.7], [5.0, 21.7], [4.6, 24.7], [5.0, 27.8], [5.4, 19.3]]
thrived = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
new_rows = [[6.4, 38.0], [5.1, 25.0]]
trees = 50
returns [1, 0]
rows = [[6.5, 42.8], [6.6, 34.6], [6.4, 38.2], [6.2, 32.4], [6.4, 34.8], [6.2, 32.6], [6.5, 39.1], [6.9, 34.9], [6.4, 41.1], [6.3, 40.6], [6.6, 39.3], [6.6, 29.9], [6.5, 37.8], [6.2, 39.8], [6.5, 40.5], [4.5, 15.8], [4.9, 25.4], [4.7, 22.5], [4.8, 19.4], [5.3, 30.0], [4.8, 25.0], [5.0, 17.2], [5.3, 22.3], [4.8, 24.3], [5.0, 21.2], [5.0, 24.7], [5.0, 21.7], [4.6, 24.7], [5.0, 27.8], [5.4, 19.3]]
thrived = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
new_rows = [[6.7, 36.0], [4.7, 20.0]]
trees = 20
returns [1, 0]

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