Decision Tree Classification#

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 MoDecisionTreeClassifier

Load and prepare dataset

ds = DataSet()
ds.load(name="TaiwanCredit")  # Changed dataset name
ds.set_random_split()
ds.set_target("FlagDefault")

Train model#

model = MoDecisionTreeClassifier(max_depth=3)  # Model initialization
model.fit(ds.train_x, ds.train_y)
MoDecisionTreeClassifier(ccp_alpha=0.0, class_weight=None, criterion='gini',
                         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
AUC ACC F1 LogLoss Brier
train 0.736758 0.820250 0.474543 0.444782 0.138957
test 0.733311 0.826333 0.473737 0.436493 0.135229
GAP -0.003448 0.006083 -0.000806 -0.008289 -0.003728


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.569 seconds)

Gallery generated by Sphinx-Gallery