FunctionRacerProblemsRace

Tune Then Test

Hardscikit-learnPython

Choosing a setting and judging the final model must use different rows, or the judgment is too kind.

1. Split X and y into training and test parts with test_size=0.3 and random_state=0.
2. On the training part only, pick the max_depth from 1 to 5 of a decision tree (random_state=0) by 4-fold cross-validation.
3. Return the accuracy on the test part of the best tree, refitted on the whole training part.

Example 1

X [[0,0],[1,3],[2,6],[3,2],[4,5],[5,1],[6,4],[7,0],[0,3],[1,6],[2,2],[3,5],[4,1],[5,4],[6,0],[7,3],[0,6],[1,2],[2,5],[3,1],[4,4],[5,0],[6,3],[7,6],[0,2],[1,5],[2,1],[3,4],[4,0],[5,3],[6,6],[7,2],[0,5],[1,1],[2,4],[3,0],[4,3],[5,6],[6,2],[7,5]]
y [0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1]
returns 1.0

The label depends on one column crossing one value, so a single question is enough and the unseen rows are all classified correctly.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More scikit-learn problems