O'Reilly logo

Python Machine Learning By Example - Second Edition by Yuxi Liu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Implementing decision tree regression

It's now time for coding after we're clear about the regression tree construction process.

The node splitting utility function we define as follow is identical to what we had in Chapter 6, Predicting Online Ads Click-through with Tree-Based Algorithms, which separates samples in a node into left and right branches based on a pair of feature and value:

>>> def split_node(X, y, index, value):...     """ Split data set X, y based on a feature and a value...     Args:...         X, y (numpy.ndarray, data set)...         index (int, index of the feature used for splitting)...         value (value of the feature used for splitting)...     Returns:...         list, list: left and right child, a child is in the                         format of [X, y]...     """... x_index = X[:, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required