Two Questions Deep

Machine Learning in CodeEasy+10 XP+10

Two Questions Deep

A teacher describes each student by [hours studied, hours slept] the night before an exam, with a label of 1 for pass and 0 for fail.

Write tree_predict(rows, passed, new_rows, depth).

  • Fit DecisionTreeClassifier(max_depth=depth, random_state=0). Trees need no scaling.
  • Predict pass or fail for every row in new_rows, in order.

Return the predictions as a list of ints.

Examples

rows = [[1.0, 5.5], [2.2, 7.1], [3.1, 4.2], [4.3, 8.0], [5.2, 6.4], [6.6, 4.9], [7.1, 7.7], [8.4, 5.8], [2.8, 8.6], [6.0, 3.6], [4.8, 4.4], [3.6, 6.9]]
passed = [0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1]
new_rows = [[7.5, 7.0], [1.5, 8.0]]
depth = 2
returns [1, 0]
rows = [[1.0, 5.5], [2.2, 7.1], [3.1, 4.2], [4.3, 8.0], [5.2, 6.4], [6.6, 4.9], [7.1, 7.7], [8.4, 5.8], [2.8, 8.6], [6.0, 3.6], [4.8, 4.4], [3.6, 6.9]]
passed = [0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1]
new_rows = [[7.5, 7.0], [1.5, 8.0]]
depth = 1
returns [1, 1]

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