Open In Colab

FuseKernel Classification

For classification FuseKernel fits the fused kernel ridge regression on one-hot targets and reads probabilities off a temperature-calibrated softmax. This example fuses the XGBoost tree co-membership kernel with a learned multi-scale spectral kernel (MS-SKM) on the TaiwanCredit dataset.

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

import warnings
warnings.filterwarnings("ignore")

import numpy as np
import pandas as pd
from modeva import DataSet, ModelZoo, TestSuite

Load and prepare dataset

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

Train FuseKernel

For classification FuseKernel fits the fused KRR on one-hot targets and reads probabilities off a temperature-calibrated softmax. Binary and multiclass are both supported, and the simplex weights are selected on the held-out query by accuracy.

from modeva.models import MoFuseKernelClassifier

model = MoFuseKernelClassifier(
    name="FuseKernel-Cls",
    use_xgb=True, use_spectral=True,
    spectral_params={"H": 4, "K": 8, "kernel": "laplace", "epochs": 50},
    interpret_ref_size=400, interpret_n_grid=20,
    random_state=0,
)

mz = ModelZoo(dataset=ds)
mz.add_model(model)
mz.train_all()
mz.leaderboard()
  0%|          | 0/1 [00:00<?, ?it/s]
100%|██████████| 1/1 [14:05<00:00, 845.40s/it]
100%|██████████| 1/1 [14:05<00:00, 845.40s/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
FuseKernel-Cls 2026-07-07 23:56:08 2026-07-08 00:04:08 480.0628 0.8152 0.7679 0.8291 0.826 0.5016 0.4706 0.4048 0.4271 0.7142 0.6874 0.3866 0.3577 0.1252 0.1328


Accuracy

AUC, accuracy, F1, log-loss and Brier, train vs test.

ts = TestSuite(ds, model)
ts.diagnose_accuracy_table().table
AUC ACC F1 LogLoss Precision Recall Brier
train 0.8152 0.8291 0.5016 0.4048 0.7142 0.3866 0.1252
test 0.7679 0.8260 0.4706 0.4271 0.6874 0.3577 0.1328
GAP -0.0473 -0.0031 -0.0311 0.0223 -0.0268 -0.0288 0.0076


Probabilities

predict_proba returns calibrated class probabilities (rows sum to 1).

proba = model.predict_proba(ds.test_x)
pd.DataFrame(proba[:5], columns=[f"P(class={c})" for c in model.classes_])
P(class=0.0) P(class=1.0)
0 0.7701 0.2299
1 0.9175 0.0825
2 0.8147 0.1853
3 0.6267 0.3733
4 0.2091 0.7909


Inherent Interpretation (FANOVA)

The same functional-ANOVA decomposition applies to the classification scores.

results = ts.interpret_fi()
results.table
Name Score
0 LIMIT_BAL 0.0111
1 SEX 0.0043
2 EDUCATION 0.0010
3 MARRIAGE 0.0098
4 AGE 0.0016
5 PAY_1 0.7275
6 PAY_2 0.0276
7 PAY_3 0.0005
8 PAY_4 0.0263
9 PAY_5 0.0138
10 PAY_6 0.0119
11 BILL_AMT1 0.0209
12 BILL_AMT2 0.0115
13 BILL_AMT3 0.0056
14 BILL_AMT4 0.0035
15 BILL_AMT5 0.0021
16 BILL_AMT6 0.0051
17 PAY_AMT1 0.0477
18 PAY_AMT2 0.0386
19 PAY_AMT3 0.0032
20 PAY_AMT4 0.0139
21 PAY_AMT5 0.0017
22 PAY_AMT6 0.0106


results = ts.interpret_ei()
results.table
Name Importance
0 LIMIT_BAL 1.1302e-02
1 SEX 2.7227e-03
2 EDUCATION 1.0350e-03
3 MARRIAGE 3.5113e-03
4 AGE 1.5979e-03
5 PAY_1 7.2309e-01
6 PAY_2 2.7998e-02
7 PAY_3 5.3384e-04
8 PAY_4 2.6617e-02
9 PAY_5 1.1177e-02
10 PAY_6 1.2105e-02
11 BILL_AMT1 2.1233e-02
12 BILL_AMT2 1.1685e-02
13 BILL_AMT3 5.6837e-03
14 BILL_AMT4 3.5341e-03
15 BILL_AMT5 2.1063e-03
16 BILL_AMT6 5.1542e-03
17 PAY_AMT1 4.8390e-02
18 PAY_AMT2 3.9166e-02
19 PAY_AMT3 3.2911e-03
20 PAY_AMT4 1.3257e-02
21 PAY_AMT5 1.7716e-03
22 PAY_AMT6 1.0775e-02
23 MARRIAGE & SEX 1.1406e-03
24 MARRIAGE & PAY_5 5.6000e-04
25 MARRIAGE & PAY_1 2.5494e-03
26 MARRIAGE & PAY_AMT4 2.8657e-04
27 MARRIAGE & BILL_AMT4 4.2774e-04
28 SEX & PAY_5 7.3412e-05
29 SEX & PAY_1 1.5988e-03
30 SEX & PAY_AMT4 4.2103e-04
31 SEX & BILL_AMT4 1.4321e-04
32 PAY_5 & PAY_1 5.0574e-03


results = ts.interpret_effects(features="PAY_1")
results.plot(results.get_figure_names()[0])


results = ts.interpret_local_fi(sample_index=1)
results.table
Name Importance Values
0 LIMIT_BAL -0.0103 500000.0000
1 SEX 0.0071 1.0000
2 EDUCATION -0.0048 1.0000
3 MARRIAGE -0.0144 2.0000
4 AGE 0.0021 29.0000
5 PAY_1 -0.0445 0.0000
6 PAY_2 -0.0083 0.0000
7 PAY_3 -0.0021 0.0000
8 PAY_4 -0.0036 0.0000
9 PAY_5 -0.0023 0.0000
10 PAY_6 -0.0068 0.0000
11 BILL_AMT1 -0.0111 5.5658
12 BILL_AMT2 0.0172 5.6149
13 BILL_AMT3 0.0250 5.6484
14 BILL_AMT4 0.0090 5.7345
15 BILL_AMT5 0.0057 5.6840
16 BILL_AMT6 -0.0161 5.6757
17 PAY_AMT1 -0.0151 4.7404
18 PAY_AMT2 -0.0392 4.6021
19 PAY_AMT3 0.0083 4.5798
20 PAY_AMT4 -0.0044 4.3062
21 PAY_AMT5 0.0007 4.1383
22 PAY_AMT6 -0.0169 4.1390


Reliability

Conformal prediction sets and coverage for the classifier.

ts.diagnose_reliability().table
Avg.Width Avg.Coverage
0 1.2383 0.904


Total running time of the script: (44 minutes 40.452 seconds)

Gallery generated by Sphinx-Gallery