Skip to main content

Bootstrap-based model stability and supervised binning toolkit

Project description

Bootstrap ML Diagnostics

A lightweight toolkit for statistically robust model diagnostics using bootstrap resampling, with utilities for:

  • supervised tree binning
  • bootstrap-based feature selection
  • model stability analysis
  • hyperparameter sensitivity analysis

The library focuses on reducing overfitting and improving model interpretability through bootstrap distributions rather than single-point estimates.


Installation

pip install maxwailab 

or

pip install git+https://github.com/MaxWienandts/maxailab.git

Core Philosophy

Most ML workflows rely on single train/validation splits.

This library instead uses bootstrap resampling to estimate:

  • performance distributions
  • feature selection stability
  • hyperparameter robustness

Benefits:

  • reduces variance from a single split
  • identifies unstable variables
  • provides confidence intervals for model performance

Workflow Overview

Typical modeling workflow using this library:

1️⃣ Supervised binning (optional)

tree_supervised_binning
bootstrap_tree_binning_auc_analysis


2️⃣ Feature selection

bootstrap_lightgbm_forward_selection


3️⃣ Diagnostics

performance_forward_selection_boxplot
variable_frequency_forward_selection


4️⃣ Extract best variables

top_k_forward_selection_variables
top_k_variables_by_forward_selection_boxplot


5️⃣ Hyperparameter analysis

lightgbm_hyperparameter_auc_curve_bootstrap

Example Workflow

import maxwailab

# --------------------------------
# Forward Selection with Bootstrap
# --------------------------------

result_bootstrap = maxwailab.bootstrap_lightgbm_forward_selection(
    df=data,
    target="target",
    n_bootstrap=30,
    n_max_variables=15,
    metric_to_optimize="auc_roc",
    hyperparameters=lgb_params
)

Analyze performance stability

bml.performance_forward_selection_boxplot(
    result_bootstrap["auc_roc"],
    "AUC"
)

This visualizes how performance behaves as variables are added.


Variable selection stability

maxwailab.variable_frequency_forward_selection(
    result_bootstrap["variables"],
    n_bootstraps=30
)

Heatmap showing how frequently variables appear in models of different sizes.


Extract best variables

Based on selection frequency

maxwailab.top_k_forward_selection_variables(
    result_bootstrap["variables"],
    n_bootstraps=30,
    k=10
)

Based on best model performance

variables, auc = maxwailab.top_k_variables_by_forward_selection_boxplot(
    result_bootstrap,
    k=6,
    metric="auc_roc"
)

Tree-based Supervised Binning

Supervised binning using decision trees.

from maxwailab import tree_supervised_binning

tree_supervised_binning(
    df=data,
    feature="age",
    target="target",
    max_leaf_nodes=5
)

Bootstrap Binning Stability

bootstrap_tree_binning_auc_analysis(
    df_train,
    df_val,
    feature="age",
    target="target"
)

Evaluates how binning performance varies across bootstrap samples.


Hyperparameter Sensitivity Analysis

Evaluate how model performance reacts to hyperparameter changes.

lightgbm_hyperparameter_auc_curve_bootstrap(
    X_train,
    y_train,
    X_val,
    y_val,
    hyperparameters=lgb_params,
    hyperparameter_name="num_leaves",
    hyperparameter_values=[5,10,20,40],
    n_bootstrap=50
)

Bootstrap is applied only to the training set while keeping validation fixed (out-of-time).


Example Output

The library produces:

  • performance distributions
  • boxplots
  • stability heatmaps
  • hyperparameter sensitivity curves

These diagnostics help detect:

  • overfitting
  • unstable features
  • fragile hyperparameters

Module Structure

maxwailab
│
├── binning
│   ├── tree_supervised_binning
│   └── bootstrap_tree_binning_auc_analysis
│
├── feature_selection
│   ├── bootstrap_lightgbm_forward_selection
│   ├── performance_forward_selection_boxplot
│   ├── variable_frequency_forward_selection
│   ├── top_k_forward_selection_variables
│   └── top_k_variables_by_forward_selection_boxplot
│
└── hyperparameter_analysis
    └── lightgbm_hyperparameter_auc_curve_bootstrap

When to Use This Library

This library is particularly useful for:

  • credit risk models
  • tabular ML problems
  • high-stakes predictive modeling
  • interpretable ML workflows

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maxwailab-1.0.4.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

maxwailab-1.0.4-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file maxwailab-1.0.4.tar.gz.

File metadata

  • Download URL: maxwailab-1.0.4.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for maxwailab-1.0.4.tar.gz
Algorithm Hash digest
SHA256 ddb52d15d1fad1d936d42644cc45a903c67f0b3f43f79f17c7cafcd86af0d978
MD5 e19cd46cd7dfd0935e02427c9acb0de4
BLAKE2b-256 9a1c3373fafee9a4ad0de034cdcdcc549aed393a1ff7fb0636ef58273b58f33f

See more details on using hashes here.

File details

Details for the file maxwailab-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: maxwailab-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for maxwailab-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 45c8aea86785093b6194be8191502f3e9abf837b6314752f2d2a44e3d8e6f183
MD5 43f8476636fc0304b3cf44a406ad183f
BLAKE2b-256 59be9318823a2cbe177b2e736e71a8e9b91e6cc620d535d1a2ae1b825be12bdd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page