Estimating the output of an electric plant using CART
Previously, we used decision trees to classify our bank contact calls (refer to the Classifying calls with decision trees recipe from Chapter 3, Classification Techniques). Classification and regression trees are the equivalent methods applied to regression problems.
Getting ready
To execute this recipe, you need pandas
and Scikit
. No other prerequisites are required.
How to do it…
Estimating CART with Scikit
is extremely easy (the regression_cart.py
file):
import sklearn.tree as sk @hlp.timeit def regression_cart(x,y): ''' Estimate a CART regressor ''' # create the regressor object cart = sk.DecisionTreeRegressor(min_samples_split=80, max_features="auto", random_state=666666, max_depth=5) # estimate the model cart.fit(x,y) # return the object return cart
How it works…
As with all the other recipes, we first load the data and extract the dependent variable y
and independent variables...