Skip to main content

BestatML

Automated, leakage-safe ensemble machine learning for Python.

BestatML provides sklearn-compatible BestatClassifier and BestatRegressor estimators that combine automatic preprocessing, heterogeneous model selection, cross-validation, out-of-fold prediction generation, tuning, stacking, and blending behind a simple API.

BestatML is designed to provide strong automated baselines and competitive ensembles. It does not claim that an ensemble will outperform every individual model on every dataset.

Contents

Features

  • Simple sklearn-style fit, predict, score, and predict_proba APIs
  • Leakage-safe preprocessing inside CV pipelines
  • Automatic numeric/categorical pandas handling
  • Missing-value imputation and unknown-safe one-hot encoding
  • Selective scaling for linear models
  • Optional low-variance filtering
  • Diverse linear, tree, forest, and gradient-boosting candidates
  • Genuine OOF predictions for comparison and meta-learning
  • Weighted blending, voting, and stacking with safe fallbacks
  • Optional CatBoost, XGBoost, and LightGBM integrations
  • Permutation-based feature importance
  • Structured training summaries and learned-model inspection
  • Reproducible random-state handling
  • Versioned persistence with artifact trust warnings
  • Extensible model registry

Installation

Once published to PyPI:

python -m pip install bestatml

Optional CatBoost/XGBoost/LightGBM integrations:

python -m pip install "bestatml[boosting]"

Development install from GitHub/source:

git clone https://github.com/xdiyorbekw/BestatML.git
cd BestatML
python -m pip install -e ".[dev]"

Quick Start

Classification

from bestatml import BestatClassifier

model = BestatClassifier(random_state=42)
model.fit(X_train, y_train)

predictions = model.predict(X_test)
probabilities = model.predict_proba(X_test)

print(model)

Regression

from bestatml import BestatRegressor

model = BestatRegressor(random_state=42)
model.fit(X_train, y_train)

predictions = model.predict(X_test)

The default workflow evaluates multiple model families with CV, generates OOF predictions, selects a compact model set, constructs an ensemble, and refits the selected pipelines on the complete training data.

Automatic Preprocessing

With a pandas DataFrame, BestatML detects numeric and categorical features and learns transformations inside each CV training fold. Numeric data uses robust median imputation by default; categorical/object/bool data can use most-frequent imputation and one-hot encoding with handle_unknown="ignore".

For linear candidates, scaling can be enabled selectively. Tree-based candidates do not need feature scaling. Optional variance filtering is also fitted inside the pipeline, so it does not inspect validation folds early.

NumPy arrays and supported scipy sparse matrices are also accepted.

Model Inspection

After fitting:

print(model)
print(model.summary())
print(model.model_scores_)
print(model.selected_models_)
print(model.ensemble_method_)

Useful learned attributes include classes_ for classification, n_features_in_, feature_names_in_, best_model_, fitted_models_, oof_predictions_, ensemble_weights_, meta_learner_, and training_summary_.

Feature importance

importance = model.get_feature_importance(
    X_test,
    y_test,
    n_repeats=5,
)
print(importance.head(10))

The result is a pandas table with feature, importance, and std columns. This uses permutation importance because the final ensemble may combine different model families.

Configuration

Important decisions remain configurable while sensible defaults keep the common path simple:

model = BestatClassifier(
    cv=5,
    scoring="roc_auc",
    ensemble_method="stacking",
    tune_hyperparameters=True,
    max_models=6,
    random_state=42,
    search_budget="balanced",
)

Search budgets provide a simple resource trade-off:

  • lightweight — smallest tuning budget
  • balanced — practical default
  • aggressive — broader tuning

Advanced users can also control model_families, disable tuning, choose an explicit ensemble method, supply a custom sklearn preprocessing transformer, and supply a custom sklearn-compatible meta learner.

Optional Boosting Libraries

CatBoost, XGBoost, and LightGBM are optional. The core package does not require them for import or baseline operation.

Install the optional group with:

python -m pip install "bestatml[boosting]"

Automatically discovered optional candidates are skipped when their packages are unavailable. When an optional family is explicitly requested and unavailable, BestatML raises a dedicated dependency error with an installation hint.

Saving and Loading

model.save("model.bestat")
loaded = BestatClassifier.load("model.bestat")

predictions = loaded.predict(X_test)

Artifacts contain fitted model state, ensemble state, learned metadata, configuration, and artifact-format metadata.

Security: persistence uses joblib. Only load artifacts you trust because Python object deserialization can execute code.

Extending the Model Registry

Advanced users can register sklearn-compatible candidates without modifying the trainer:

from bestatml.models import ModelSpec, register_model
from sklearn.linear_model import LogisticRegression

register_model(ModelSpec(
    name="my_classifier",
    family="linear",
    tasks=("classification",),
    probability=True,
    factory=lambda random_state, n_jobs: LogisticRegression(
        max_iter=2000,
        random_state=random_state,
    ),
))

sklearn Compatibility

Both estimators expose explicit constructor parameters and follow sklearn estimator conventions. They can be cloned and inspected through get_params()/set_params(), used in sklearn pipelines, and placed inside outer model-selection workflows.

BestatML's own CV remains part of the estimator training lifecycle so learned preprocessing is fitted only where allowed by the relevant fold.

Error Handling

BestatML validates configuration, training data, target data, and inference schemas before deeper ML operations whenever practical. Important exception types are available from the package root:

from bestatml import BestatMLDataError, BestatMLConfigurationError

Messages identify the problem and provide a concrete correction when possible. Wrapped lower-level failures retain their original cause for debugging.

Documentation

The README is intentionally a practical introduction rather than the full reference manual. A separate documentation site can provide the exhaustive API reference, configuration reference, architecture notes, and tutorials in the future.

License

BestatML is released under the MIT License. See LICENSE.

Download files

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

Source Distribution

bestatml-0.1.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

bestatml-0.1.1-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file bestatml-0.1.1.tar.gz.

File metadata

  • Download URL: bestatml-0.1.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0rc1

File hashes

Hashes for bestatml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4029726d4f30ea592fbcc0a0b6fa1e0cf64c69a384bf26280eeb87ae142a78cc
MD5 d8110424355786cbfe83e372ca6402e8
BLAKE2b-256 8217aa6fb853769f3ae46daa7c17aaa25e706857e48a60c3f0962c5097ce04e6

See more details on using hashes here.

File details

Details for the file bestatml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bestatml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.0rc1

File hashes

Hashes for bestatml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f3d7f687a4ed2dd36ec2d05301edcef0497c04c5a633c1a6bb90474de640dc66
MD5 dd28c18975d3d30554c3bb636aeafa26
BLAKE2b-256 497fc8201897e8a259338c05926fc945b2f34c07f518ebb901d3d035f359cd44

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page