Open In Colab

ModelZoo

This example demonstrates how to use ModelZoo to manage multiple models, train them, and perform various analyses using TestSuite.

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 lightgbm import LGBMClassifier

from modeva import DataSet
from modeva import ModelZoo
from modeva import TestSuite
from modeva.utils.mlflow import set_mlflow_home, get_mlflow_home
from modeva.models.local_model_zoo import LocalModelZoo
from modeva.models.wrappers.api import modeva_sklearn_classifier

# Import model classes
from modeva.models import (
    MoLogisticRegression, MoDecisionTreeClassifier,
    MoLGBMClassifier, MoXGBClassifier, MoCatBoostClassifier,
    MoRandomForestClassifier, MoGradientBoostingClassifier,
    MoGAMINetClassifier, MoReLUDNNClassifier,
    MoGLMTreeBoostClassifier, MoNeuralTreeClassifier
)

Configure MLflow settings

set_mlflow_home(mlflow_home="~/modeva_mlflow")
mlflow_home = get_mlflow_home()

Load and prepare dataset

ds = DataSet()
ds.load(name="TaiwanCredit")
ds.set_random_split()

Initialize ModelZoo

mz = LocalModelZoo(name="TaiwanCredit-Exp", dataset=ds)
print(f"Experiment name: {mz.experiment_name}")
print(f"Experiment ID: {mz.experiment_id}")
Experiment name: TaiwanCredit-Exp
Experiment ID: 3

Add traditional ML models

mz.add_model(model=MoLGBMClassifier(name="LGBM2", max_depth=2, verbose=-1))
mz.add_model(model=MoXGBClassifier(name="XGB2", max_depth=2))
mz.add_model(model=MoCatBoostClassifier(name="CatBoost2", max_depth=2, silent=True))
mz.add_model(model=MoRandomForestClassifier(name="RF2", max_depth=2))
mz.add_model(model=MoGradientBoostingClassifier(name="GBDT2", max_depth=2))
mz.add_model(model=MoLogisticRegression(
    name="LR",
    feature_names=ds.feature_names,
    feature_types=ds.feature_types
))
mz.add_model(model=MoDecisionTreeClassifier(name="DT", max_depth=8))
mz.add_model(model=MoReLUDNNClassifier(name="ReLUDNN"))

Add advanced ML models

mz.add_model(model=MoNeuralTreeClassifier(
    name="NeuralTree",
    nn_temperature=0.001,
    nn_max_epochs=100,
    verbose=False,
    random_state=0
))

Add wrapped scikit-learn model

wrap_estimator = modeva_sklearn_classifier(
    name="LGBM-wrapped",
    estimator=LGBMClassifier(verbose=-1)
)
mz.add_model(model=wrap_estimator)

Train all models and show leaderboard

mz.train_all()
mz.leaderboard(order_by="test AUC")
  0%|          | 0/10 [00:00<?, ?it/s]
 10%|█         | 1/10 [00:00<00:03,  2.40it/s]
 20%|██        | 2/10 [00:00<00:02,  3.17it/s]
 30%|███       | 3/10 [00:06<00:20,  2.92s/it]
 40%|████      | 4/10 [00:07<00:13,  2.25s/it]
 50%|█████     | 5/10 [00:13<00:17,  3.44s/it]
 60%|██████    | 6/10 [00:13<00:09,  2.38s/it]
 70%|███████   | 7/10 [00:14<00:05,  1.68s/it]
 80%|████████  | 8/10 [00:18<00:05,  2.50s/it]
 90%|█████████ | 9/10 [00:29<00:05,  5.20s/it]
100%|██████████| 10/10 [00:30<00:00,  3.80s/it]
100%|██████████| 10/10 [00:30<00:00,  3.01s/it]
start_time end_time Duration train AUC test AUC train ACC test ACC train F1 test F1 train LogLoss test LogLoss train Precision test Precision train Recall test Recall train Brier test Brier
LGBM-wrapped 2026-07-07 23:53:07 2026-07-07 23:53:07 0.326342 0.880594 0.786645 0.843542 0.827667 0.550138 0.486594 0.358546 0.417972 0.763298 0.683403 0.430043 0.377795 0.110928 0.130323
CatBoost2 2026-07-07 23:52:38 2026-07-07 23:52:43 5.141667 0.79973 0.783806 0.822125 0.8265 0.481603 0.478718 0.417952 0.420297 0.684738 0.682857 0.371418 0.368543 0.130917 0.131006
XGB2 2026-07-07 23:52:38 2026-07-07 23:52:38 0.102424 0.802168 0.783313 0.823417 0.829167 0.487297 0.487756 0.416518 0.420393 0.688077 0.693182 0.377224 0.376253 0.130687 0.131044
GBDT2 2026-07-07 23:52:45 2026-07-07 23:52:51 5.316097 0.791414 0.78185 0.821208 0.831 0.476388 0.486322 0.424638 0.421141 0.683473 0.70901 0.365612 0.370085 0.133016 0.130998
LGBM2 2026-07-07 23:52:38 2026-07-07 23:52:38 0.142487 0.789608 0.780283 0.820542 0.83 0.472634 0.48118 0.425528 0.421604 0.682461 0.707025 0.361491 0.364688 0.133381 0.131115
RF2 2026-07-07 23:52:44 2026-07-07 23:52:45 0.873908 0.768075 0.772251 0.800917 0.807 0.271202 0.26616 0.456669 0.448526 0.730485 0.747331 0.166511 0.161912 0.144133 0.140648
DT 2026-07-07 23:52:51 2026-07-07 23:52:52 0.173586 0.796572 0.759657 0.832833 0.8225 0.510851 0.459665 0.408532 0.62687 0.73175 0.672107 0.392396 0.349268 0.126704 0.137623
LR 2026-07-07 23:52:51 2026-07-07 23:52:51 0.142572 0.736877 0.73709 0.801917 0.8075 0.346619 0.338867 0.464723 0.453707 0.651007 0.657778 0.236187 0.228219 0.146964 0.142926
NeuralTree 2026-07-07 23:52:56 2026-07-07 23:53:07 10.956044 0.677314 0.690829 0.78275 0.791333 0.084942 0.103152 3.548729 3.315473 0.674095 0.727273 0.045327 0.055513 0.204765 0.195977
ReLUDNN 2026-07-07 23:52:52 2026-07-07 23:52:56 4.147365 0.652179 0.666317 0.751042 0.757667 0.37244 0.380222 1.6562 1.528116 0.42396 0.425167 0.332085 0.34387 0.206373 0.197916


Model interpretation examples

Feature importance analysis

model = mz.get_model("ReLUDNN")
ts = TestSuite(ds, model)
results = ts.interpret_fi()
results.plot()


Feature effects analysis for different models

model = mz.get_model("LGBM2")
ts = TestSuite(ds, model)
results = ts.interpret_effects(features="PAY_1")
results.plot()


Model registration and loading

Register all models

for name in mz.models.keys():
    mz.register(name)

# List registered models
registered_models = mz.list_registered_models()
print("Registered models:", registered_models)
Registered models:             Name  Latest Version
0      CatBoost2               1
1             DT               1
2          GBDT2               1
3           LGBM               2
4   LGBM-wrapped               1
5          LGBM2               1
6     LGMB-Tuned               2
7             LR               1
8     NeuralTree               1
9            RF2               1
10       ReLUDNN               1
11          XGB2               1

Load and verify registered models

ds_new = DataSet()
ds_new.load(name="TaiwanCredit")
ds_new.set_random_split()
mz_new = ModelZoo(name="TaiwanCredit-Exp", dataset=ds_new)

# Verify predictions from loaded models
for name in mz.models.keys():
    loaded_model = mz_new.load_registered_model(name)
    predictions = loaded_model.predict_proba(ds_new.train_x)
    print(f"Model {name} predictions shape: {predictions.shape}")
Model LGBM2 predictions shape: (24000, 2)
Model XGB2 predictions shape: (24000, 2)
Model CatBoost2 predictions shape: (24000, 2)
Model RF2 predictions shape: (24000, 2)
Model GBDT2 predictions shape: (24000, 2)
Model LR predictions shape: (24000, 2)
Model DT predictions shape: (24000, 2)
Model ReLUDNN predictions shape: (24000, 2)
Model NeuralTree predictions shape: (24000, 2)
Model LGBM-wrapped predictions shape: (24000, 2)

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

Gallery generated by Sphinx-Gallery