Train your first regression tree
In this exercise, you'll train a regression tree to predict the mpg
(miles per gallon) consumption of cars in the auto-mpg dataset using all the six available features.
The dataset is processed for you and is split to 80% train and 20% test. The features matrix X_train
and the array y_train
are available in your workspace.
This exercise is part of the course
Machine Learning with Tree-Based Models in Python
Exercise instructions
- Import
DecisionTreeRegressor
fromsklearn.tree
. - Instantiate a
DecisionTreeRegressor
dt
with maximum depth 8 andmin_samples_leaf
set to 0.13. - Fit
dt
to the training set.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Import DecisionTreeRegressor from sklearn.tree
from ____.____ import ____
# Instantiate dt
____ = ____(max_depth=____,
____=____,
random_state=3)
# Fit dt to the training set
____.____(____, ____)