HNBM
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).
Table of Contents
Installation
From PyPI:
pip install hnbm
From source:
git clone https://github.com/qiancapital-dev/hnbm.git
cd hnbm
pip install .
Requirements: Python ≥ 3.8, NumPy, scikit-learn, tqdm.
Quick Start
Subclass HNBMClassifier or HNBMRegressor and configure your base learner pool before training:
Classification
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from hnbm import HNBMClassifier
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 TreeClassifier(HNBMClassifier):
def __init__(self, max_depth=5, **kwargs):
super().__init__(**kwargs)
self.base_learners_ = [DecisionTreeRegressor(max_depth=max_depth)]
self.probabilities_ = [1.0]
model = TreeClassifier(
num_iterations=100,
learning_rate=0.1,
random_state=42,
)
model.fit(X_train, y_train)
print("Accuracy:", model.score(X_test, y_test))
print("Probabilities shape:", model.predict_proba(X_test).shape) # (n_samples, 2)
model.evaluate(X_test, y_test) # prints log loss
Regression
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from hnbm import HNBMRegressor
X, y = load_diabetes(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=42)
class TreeRegressor(HNBMRegressor):
def __init__(self, max_depth=5, **kwargs):
super().__init__(**kwargs)
self.base_learners_ = [DecisionTreeRegressor(max_depth=max_depth)]
self.probabilities_ = [1.0]
model = TreeRegressor(
num_iterations=100,
learning_rate=0.1,
random_state=42,
)
model.fit(X_train, y_train)
print("R²:", model.score(X_test, y_test))
model.evaluate(X_test, y_test) # prints RMSE
API Reference
HNBMClassifier / HNBMRegressor
The recommended entry points (similar to XGBClassifier / XGBRegressor). Subclass one of these and set base_learners_ (list of unfitted sklearn regressors) and probabilities_ (list summing to 1) before calling fit.
Methods
| Method | Classifier | Regressor | Description |
|---|---|---|---|
fit(X, y) |
✓ | ✓ | Train the ensemble |
predict(X) |
✓ | ✓ | Class labels (0/1) or continuous values |
predict_proba(X) |
✓ | Probabilities, shape (n_samples, 2) |
|
decision_function(X) |
✓ | Raw logits | |
score(X, y) |
✓ | ✓ | Accuracy or R² |
evaluate(X, y) |
✓ | ✓ | Prints and returns log loss or RMSE |
HNBM
Legacy base class that accepts a mode parameter ("classification" or "regression"). Prefer HNBMClassifier or HNBMRegressor for new code.
from sklearn.tree import DecisionTreeRegressor
from hnbm import HNBM
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", # or "regression"
random_state=42,
)
model.fit(X_train, y_train)
Loss functions
hnbm.losses provides Logistic (classification) and MeanSquaredError (regression), each with a compute_derivatives(y, f) method returning gradient and Hessian vectors.
Parameters
Shared (HNBMClassifier / HNBMRegressor)
| Parameter | Type | Default | Description |
|---|---|---|---|
num_iterations |
int |
100 |
Number of boosting rounds |
learning_rate |
float |
0.1 |
Shrinkage per learner |
random_state |
int or None |
None |
Seed for learner selection |
verbose |
bool |
True |
Show tqdm progress bar |
The legacy HNBM class also accepts a mode parameter ("classification" or "regression").
Label conventions (classification): accepts 0/1 or -1/+1. Predictions are returned as 0/1.
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 RFF 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hnbm-0.1.1.tar.gz.
File metadata
- Download URL: hnbm-0.1.1.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d980e06cc3d6e7f18b79527b95fe158072f23f487026df9b436267fd6b8df9e
|
|
| MD5 |
433fbca10932bec812288f42f6818fea
|
|
| BLAKE2b-256 |
06268f15c7a348eb09996285f14219d7f970179c9d3dfcaad44de8623a62f000
|
Provenance
The following attestation bundles were made for hnbm-0.1.1.tar.gz:
Publisher:
python-publish.yml on QianCapital/hnbm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hnbm-0.1.1.tar.gz -
Subject digest:
7d980e06cc3d6e7f18b79527b95fe158072f23f487026df9b436267fd6b8df9e - Sigstore transparency entry: 2333077812
- Sigstore integration time:
-
Permalink:
QianCapital/hnbm@b938c6d0c64ba5c6ecc3689d0ebd3eedeb3ec1bf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/QianCapital
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b938c6d0c64ba5c6ecc3689d0ebd3eedeb3ec1bf -
Trigger Event:
release
-
Statement type:
File details
Details for the file hnbm-0.1.1-py3-none-any.whl.
File metadata
- Download URL: hnbm-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1a71e456dae2e3361f9b67c2866c792ec8a0bbe1f7e12d030bf0a2e34d32ef4
|
|
| MD5 |
871d2b0dbeebedc0af017033a706659a
|
|
| BLAKE2b-256 |
ee1a1e1510c0b0e82a1a4ac60bea36003a6c548ef1a61db7d556dfa59c5d05f6
|
Provenance
The following attestation bundles were made for hnbm-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on QianCapital/hnbm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hnbm-0.1.1-py3-none-any.whl -
Subject digest:
c1a71e456dae2e3361f9b67c2866c792ec8a0bbe1f7e12d030bf0a2e34d32ef4 - Sigstore transparency entry: 2333077833
- Sigstore integration time:
-
Permalink:
QianCapital/hnbm@b938c6d0c64ba5c6ecc3689d0ebd3eedeb3ec1bf -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/QianCapital
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b938c6d0c64ba5c6ecc3689d0ebd3eedeb3ec1bf -
Trigger Event:
release
-
Statement type: