Skip to main content

HNBM

License: MIT scikit-learn

Heterogeneous Newton Boosting Machine (HNBM) — a scikit-learn-compatible gradient boosting framework that stochastically mixes heterogeneous base learners at each iteration.

Unlike standard gradient boosting libraries that use a single learner type (typically decision trees), HNBM lets you define a pool of base learners with selection probabilities. At each boosting round, a learner is drawn from that pool and fit to the Newton step (gradient divided by Hessian, weighted by the Hessian).

This is the core framework behind SnapBoost, inspired by SnapBoost: A Heterogeneous Boosting Machine (Parnell et al., NeurIPS 2020).


Installation

From source (recommended until PyPI release):

git clone https://github.com/qiancapital-dev/hnbm.git
cd hnbm
pip install .

Requirements: Python ≥ 3.8, NumPy, scikit-learn, tqdm.


Quick Start

Subclass HNBM and configure your base learner pool before training:

from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from hnbm import HNBM

X, y = load_breast_cancer(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)


class TreeBoost(HNBM):
    def __init__(self, max_depth=5, **kwargs):
        super().__init__(**kwargs)
        self.base_learners_ = [DecisionTreeRegressor(max_depth=max_depth)]
        self.probabilities_ = [1.0]


model = TreeBoost(
    num_iterations=100,
    learning_rate=0.1,
    mode="classification",
    random_state=42,
)
model.fit(X_train, y_train)

print("Accuracy:", model.score(X_test, y_test))
model.evaluate(X_test, y_test)

API Reference

HNBM

Parameter Type Default Description
num_iterations int 100 Number of boosting rounds
learning_rate float 0.1 Shrinkage per learner
mode str "classification" "classification" or "regression"
random_state int or None None Seed for learner selection
verbose bool True Show tqdm progress bar

Methods

Method Mode Description
fit(X, y) both Train the ensemble
predict(X) both Class labels (0/1) or continuous values
predict_proba(X) classification Probabilities, shape (n_samples, 2)
decision_function(X) classification Raw logits
score(X, y) both Accuracy or R²
evaluate(X, y) both Prints and returns log loss or RMSE

Subclass contract: set base_learners_ (list of unfitted sklearn regressors) and probabilities_ (list summing to 1) before calling fit.

Loss functions

hnbm.losses provides Logistic (classification) and MeanSquaredError (regression), each with a compute_derivatives(y, f) method returning gradient and Hessian vectors.


Docker

docker build -t hnbm .
docker run --rm hnbm

Development

git clone https://github.com/qiancapital-dev/hnbm.git
cd hnbm
pip install -r requirements.txt
pip install -e .

Related projects

  • snapboost — a concrete HNBM using decision trees and kernel ridge regressors

License

MIT — See LICENSE for full text.

Download files

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

Source Distribution

hnbm-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

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

hnbm-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file hnbm-0.1.0.tar.gz.

File metadata

  • Download URL: hnbm-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for hnbm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 032e6974691d54ae52c8518d2d0c45c00b5fe63d6375437f245e7c1b13328509
MD5 415505572bb7fae054cea831de164ef7
BLAKE2b-256 2503a4684d9185caa4fd0344831e0c0cede713f45b66c5eac97275f356ab4c7f

See more details on using hashes here.

File details

Details for the file hnbm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hnbm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for hnbm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d19f39d904e467b8b9cbba342dfdb18e331d46da0721a328280087d1e5e67947
MD5 e4ce8584b25eeb640b7160bd7764097b
BLAKE2b-256 a6f88679d5ff6035f3c81588e7c97f11920a58dd2605c0d7c61a93bcf396cda7

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