Decision Tree Regression#

Installation

# To install the required package, use the following command:
# !pip install modeva

Authentication

# To get authentication, use the following command: (To get full access please replace the token to your own token)
# from modeva.utils.authenticate import authenticate
# authenticate(auth_code='eaaa4301-b140-484c-8e93-f9f633c8bacb')

Import required modules

from modeva import DataSet
from modeva import TestSuite
from modeva.models import MoDecisionTreeRegressor

Load and prepare dataset

ds = DataSet()
ds.load(name="BikeSharing")  # Changed dataset name
ds.set_random_split()
ds.set_target("cnt")

ds.scale_numerical(features=("cnt",), method="log1p")
ds.preprocess()

Train model#

model = MoDecisionTreeRegressor(max_depth=3)
model.fit(ds.train_x, ds.train_y)
MoDecisionTreeRegressor(ccp_alpha=0.0, criterion='squared_error', max_depth=3,
                        max_features=None, max_leaf_nodes=None,
                        min_impurity_decrease=0.0, min_samples_leaf=1,
                        min_samples_split=2, min_weight_fraction_leaf=0.0,
                        random_state=None, splitter='best')
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.


Basic accuracy analysis#

ts = TestSuite(ds, model)
results = ts.diagnose_accuracy_table()
results.table
MSE MAE R2
train 0.555878 0.579652 0.723022
test 0.603628 0.600893 0.701683
GAP 0.047750 0.021241 -0.021339


Global tree interpretation#

results = ts.interpret_global_tree()
results.plot()


Local tree interpretation#

results = ts.interpret_local_tree(sample_index=0)
results.plot()


Total running time of the script: (0 minutes 0.306 seconds)

Gallery generated by Sphinx-Gallery