Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Machine Learning with Tree-Based Models in Python

Cursus bekijken

Oefeninstructies

  • Import DecisionTreeRegressor from sklearn.tree.
  • Instantiate a DecisionTreeRegressor dt with maximum depth 8 and min_samples_leaf set to 0.13.
  • Fit dt to the training set.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Import DecisionTreeRegressor from sklearn.tree
from ____.____ import ____

# Instantiate dt
____ = ____(max_depth=____,
             ____=____,
            random_state=3)

# Fit dt to the training set
____.____(____, ____)
Code bewerken en uitvoeren