Skip to main content

TowerGB

TowerGB is a fast, enterprise-ready machine learning model for tabular classification. It features a dual-tower ensemble architecture with built-in probability calibration, feature importance attribution, class balancing, and sub-millisecond inference.

CI Python 3.9+ License: MIT


How It Works

TowerGB works in four steps:

  1. Tower 1 (Accuracy): Trains bootstrap passes and evaluates accuracy.
  2. Tower 2 (Risk & Calibration): Evaluates log-loss, Brier score, and sample-wise loss variance.
  3. Pareto Arbiter: Computes optimal ensemble voting weights based on accuracy and risk.
  4. Temperature Calibration: Minimizes Expected Calibration Error (ECE) via Golden Section Search.

Key Features

  • Zero Heavy Dependencies: Pure NumPy and Scikit-Learn.
  • Sub-Millisecond Latency: 0.09 ms per batch inference via single collapsed matrix multiplication.
  • Feature Importances & Coefficients: Full interpretability via .feature_importances_, .coef_, and .intercept_.
  • Imbalanced Data Ready: Built-in class_weight='balanced' and sample_weight support.
  • L2 Regularization: Built-in weight decay (l2_reg) to prevent overfitting.
  • Parallel Training: Native multi-core CPU scaling (n_jobs=-1).
  • Scikit-Learn Standard: 100% compliant with Pipeline, GridSearchCV, cross_val_score, and serialization.

Installation

# Clone the repository
git clone https://github.com/anishupr47-git/TableGB.git
cd TableGB

# Create a virtual environment
python -m venv .venv

# Activate on Windows:
.venv\Scripts\activate

# Or activate on macOS/Linux:
# source .venv/bin/activate

# Install the package
pip install -e ".[test]"

Quick Example

from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from towergb import TowerGBClassifier

# 1. Create example table data
X, y = make_classification(n_samples=1000, n_features=20, n_classes=3,
                           n_informative=10, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

# 2. Create and train the model with L2 regularization and balanced weights
clf = TowerGBClassifier(n_passes=5, learning_rate=0.1, l2_reg=1e-4, random_state=42)
clf.fit(X_train, y_train)

# 3. Check accuracy
print(f"Accuracy: {clf.score(X_test, y_test):.4f}")

# 4. View feature importance ranking
print(f"Top feature importance: {clf.feature_importances_[:5]}")

# 5. Tune confidence probabilities
clf.calibrate(X_test, y_test)
proba = clf.predict_proba(X_test)
print(f"Calibrated probabilities shape: {proba.shape}")

Settings and Options

TowerGBClassifier Parameters

Parameter Type Default Description
n_passes int 5 Number of ensemble passes
learning_rate float 0.1 Gradient descent learning rate
max_iter int 300 Maximum iterations per pass
temperature float 1.0 Initial softmax temperature
l2_reg float 1e-4 L2 weight regularization penalty
subsample_ratio float 1.0 Subsampling ratio per pass
class_weight str | dict | None None Class balancing (e.g. 'balanced')
tol float 1e-6 Convergence tolerance
random_state int | None None Random seed
arbiter_weights dict | None None Multi-objective Pareto arbiter weights
n_jobs int | None None CPU cores for parallel pass training

Public Attributes

Attribute Type Description
classes_ ndarray Unique class labels
n_features_in_ int Number of features seen during fit
feature_importances_ ndarray Normalized importance score per feature (sums to 1.0)
coef_ ndarray Learned feature weight coefficients
intercept_ ndarray Learned bias intercepts
temperature_ float Calibrated softmax temperature
n_iter_ ndarray Iterations executed per pass

Main Methods

Method Description
.fit(X, y, sample_weight=None) Train the ensemble
.predict(X) Predict class label
.predict_proba(X) Calibrated probability estimates
.calibrate(X_val, y_val) Post-hoc ECE temperature optimization
.score(X, y, sample_weight=None) Accuracy score

Running Tests

# Run all tests
pytest tests/ -v

# Run with test coverage
pytest tests/ -v --cov=towergb --cov-report=term-missing

Running Benchmarks

# Install benchmark tools
pip install -e ".[benchmark]"

# Run speed and accuracy comparison
python benchmarks/run_benchmarks.py

License

MIT

Download files

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

Source Distribution

towergb-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

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

towergb-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: towergb-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.7

File hashes

Hashes for towergb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d7978e7aff3d3e1f6692da9cbe81c62e49be9bc835a2303262aed214e198b662
MD5 54acbf3c204957d8d4b6824049a24709
BLAKE2b-256 42b4f6fa0a691e15d4a9aebe2bb76ed0cd0380aa505f8026d2b24c1dfb4d5528

See more details on using hashes here.

File details

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

File metadata

  • Download URL: towergb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.7

File hashes

Hashes for towergb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 117606a9a5817f46126294c696652492bd1a13c67b0033a451b30d5144bb59a6
MD5 c0a87d1bf6325bec53cc0334e88c2e08
BLAKE2b-256 2e63c0fa3390756da851fa08977fa20043d2f9e71308cc5c334712cd5202d026

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

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