Note
Go to the end to download the full example code or to run this example in your browser via Binder
Tree Classification (TaiwanCredit)¶
Experiment initialization and data preparation
from piml import Experiment
from piml.models import TreeClassifier
exp = Experiment()
exp.data_loader(data="TaiwanCredit", silent=True)
exp.data_summary(feature_exclude=["LIMIT_BAL", "SEX", "EDUCATION", "MARRIAGE", "AGE"], silent=True)
exp.data_prepare(target="FlagDefault", task_type="classification", silent=True)
Train Model
exp.model_train(model=TreeClassifier(max_depth=6), name="Tree")
Evaluate predictive performance
exp.model_diagnose(model="Tree", show="accuracy_table")
ACC AUC F1 LogLoss Brier
Train 0.8248 0.7716 0.4872 0.4281 0.1334
Test 0.8255 0.7605 0.4715 0.4537 0.1342
Gap 0.0007 -0.0111 -0.0157 0.0256 0.0008
Global interpretation starting from the root node
exp.model_interpret(model="Tree", show="tree_global", root=0, depth=3,
original_scale=True, figsize=(16, 10))
Global interpretation starting from the 10-th node
exp.model_interpret(model="Tree", show="tree_global", root=2, depth=3,
original_scale=True, figsize=(16, 10))
Local interpretation
exp.model_interpret(model="Tree", show="tree_local", sample_id=0,
original_scale=True, figsize=(16, 10))
Total running time of the script: ( 0 minutes 37.505 seconds)
Estimated memory usage: 34 MB