5.1. Exercises
Regression with Decision Tree True or False
Building a Decision Tree Regressor
Instructions:
Running a coding exercise for the first time could take a bit of time for everything to load. Be patient, it could take a few minutes.
When you see ____ in a coding exercise, replace it with what you assume to be the correct code. Run it and see if you obtain the desired output. Submit your code to validate if you were correct.
Make sure you remove the hash (#) symbol in the coding portions of this question. We have commented them so that the line wonโt execute and you can test your code after each step.
Letโs build a decision tree regressor using DecisionTreeRegressor() and letโs set some different hyperparameters.
Tasks:
- Build a model using
DecisionTreeRegressor()and make sure to set the argumentrandom_stateto 1. - Set the
max_depthof the tree to 8.
- Save your model in an object named
reg_tree. - Fit your model on the objects
Xandyand then predict onX. - Save the R^2 score of the model rounded to 2 decimal places in a variable named
tree_score.