We will use the Boston House Prices dataset from scikit-learn. The target in this dataset is continuous, therefore, we will train a decision tree for regression with DecisionTreeRegressor() from scikit-learn:
- Let's import the required Python libraries, classes and dataset:
import pandas as pdimport matplotlib.pyplot as pltfrom sklearn.datasets import load_bostonfrom sklearn.model_selection import train_test_splitfrom sklearn.tree import DecisionTreeRegressorfrom feature_engine.discretisers import DecisionTreeDiscretiser
- Let's load the Boston House Prices dataset into a pandas dataframe:
boston_dataset = load_boston()data = pd.DataFrame(boston_dataset.data, columns=boston_dataset.feature_names)data['MEDV'] = boston_dataset.target ...