Open In Colab

Tree Ensemble Models (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 (MoLGBMRegressor,
                           MoXGBRegressor,
                           MoCatBoostRegressor,
                           MoGradientBoostingRegressor,
                           MoRandomForestRegressor)

Load and prepare dataset

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

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

Train model

You may replace the model by anyone of the following, including MoGradientBoostingRegressor, MoRandomForestRegressor, MoXGBRegressor, MoCatBoostRegressor

model = MoLGBMRegressor(max_depth=2, verbose=-1, random_state=0)
model.fit(ds.train_x, ds.train_y.ravel())
MoLGBMRegressor(boosting_type='gbdt', class_weight=None, colsample_bytree=1.0,
                importance_type='split', learning_rate=0.1, max_depth=2,
                min_child_samples=20, min_child_weight=0.001,
                min_split_gain=0.0, n_estimators=100, n_jobs=None,
                num_leaves=31, objective=None, random_state=0, reg_alpha=0.0,
                reg_lambda=0.0, subsample=1.0, subsample_for_bin=200000,
                subsample_freq=0, verbose=-1)
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.2786 0.4043 0.8612
test 0.2870 0.4100 0.8582
GAP 0.0084 0.0057 -0.0030


Feature importance analysis

results = ts.interpret_fi()
results.plot()


Effect importance analysis

results = ts.interpret_ei()
results.plot(n_bars=10)


Local feature importance analysis

results = ts.interpret_local_fi(dataset='train', sample_index=1, centered=True)
results.plot(n_bars=10)


Local effect importance analysis

results = ts.interpret_local_ei(dataset='train', sample_index=1)
results.plot(n_bars=10)


Main effect plot

For numerical feature

results = ts.interpret_effects(features="hr")
results.plot()


For categorical feature

results = ts.interpret_effects(features="season")
results.plot()


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

Gallery generated by Sphinx-Gallery