How it works...
To perform discretization with decision trees, we first loaded the dataset and divided it into train and test sets using the scikit-learn train_test_split() function. Next, we chose a variable, LSTAT, and fit a decision tree for regression using DecisionTreeRegressor() from scikit-learn. We used to_frame() to transform the pandas Series with the variable into a dataframe and make the data compatible with scikit-learn predictors. We used the fit() method to make the tree learn how to predict the MEDV target from LSTAT. With the predict() method, the tree estimated the target from LSTAT in the train and test sets. The decision tree returned eight distinct values, which were its predictions. These outputs represented the bins ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access