Skip to main content

routernet

Per-sample specialist routing ensemble with learned context awareness.

routernet is a scikit-learn compatible ensemble algorithm. It trains a pool of diverse specialist models and a learned gating network that routes each sample to the specialists best suited for it, based on a learned 16-dimensional context embedding (neighborhood geometry, feature statistics, label structure and specialist agreement).

Installation

pip install routernet

Core dependencies are kept minimal: numpy, scipy, pandas, scikit-learn. Install the optional boosting specialists (cat/xgb) with:

pip install routernet[boost]      # xgboost, lightgbm, catboost

Quick start

from routernet import RouternetClassifier
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

X, y = make_classification(n_samples=500, n_features=20, n_informative=12,
                           n_classes=3, random_state=42)
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=0.2, random_state=42)

clf = RouternetClassifier(n_specialists=3, random_state=42)
clf.fit(X_tr, y_tr)
print(f"Accuracy: {accuracy_score(y_te, clf.predict(X_te)):.3f}")

Regression works the same way with RouternetRegressor.

How it works

  1. Specialists — a pool of diverse models (gb, rf, svm, mlp, dt, et, cat, xgb, or any scikit-learn estimator) are trained. Out-of-fold (OOF) predictions avoid leakage when training the gate.
  2. Context encoder — each sample is embedded into 16 features describing its local neighborhood, feature statistics and specialist agreement.
  3. Gating network — a small MLP (trained with the built-in autograd engine) maps context embeddings to per-sample specialist weights by directly optimizing the ensemble cross-entropy loss.
  4. Confidence gate — a learned per-sample fallback blends in the uniform ensemble when routing would be unreliable.

Because everything is a BaseEstimator, RouternetClassifier / RouternetRegressor work in Pipelines, GridSearchCV, and OpenML's run_model_on_task.

Interpretability

weights = clf.get_specialist_weights(X)   # per-sample specialist weights
context = clf.get_context(X)              # 16-dim context embeddings
analysis = analyze_routing(clf, X, y)     # routing summary
print_routing_analysis(analysis)

Legacy v1

The original v1 implementation is kept for reproducibility in routernet.legacy (LegacyRouternetClassifier, LegacyRouternetRegressor).

Development

pip install -e ".[dev]"
make test       # pytest + coverage
make lint       # ruff
make build      # sdist + wheel
make check      # twine check

Benchmarking on OpenML

The OpenML-CC18 benchmark lives outside this package in benchmarks/ and is not shipped on PyPI. It runs a performance gate before the full run and publishes to OpenML only if routernet performs well:

pip install -r benchmarks/requirements.txt
export OPENML_API_KEY=YOUR_OPENML_API_KEY
python benchmarks/openml_benchmark.py --gate-tasks 6 --limit 10

See benchmarks/README.md for details.

License

Apache 2.0 — see LICENSE.

Metadata

Release files for routernet 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for routernet 0.1.0
File Size Uploaded
routernet-0.1.0.tar.gz 27.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for routernet 0.1.0
File Interpreter ABI Platform
routernet-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 58.2 kB

Release files / routernet-0.1.0.tar.gz

Download URL routernet-0.1.0.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9bca92226799d238121a93fa0cea054f9a66417a2b474756a964736842315c55
BLAKE2b-256 checksum
How to use checksums
9b79039179fa1cd7a5d39500e96eaee2897d2ce01e17fecc01740ec495adbb2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release files / routernet-0.1.0-py3-none-any.whl

Download URL routernet-0.1.0-py3-none-any.whl
Size 30.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da9b8d58b4853b9812d3a72d7dac6b9d469f5dc12583b00c89019b3a5eeb095d
BLAKE2b-256 checksum
How to use checksums
5477926ece7b1804d1b2d64ed9ceb26805eb89560c0a07bda6ee0c5f629b66e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release 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