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
- 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. - Context encoder — each sample is embedded into 16 features describing its local neighborhood, feature statistics and specialist agreement.
- 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.
- 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)
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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| routernet-0.1.1.tar.gz | 26.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| routernet-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.1 kB
Release files / routernet-0.1.1.tar.gz
| Download URL | routernet-0.1.1.tar.gz |
|---|---|
| Size | 26.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
49d7aa4f0e49f1116d6e413cc261de5fa19a8a4f2deb50ba10e0d7b5be80252a
|
|
BLAKE2b-256 checksum How to use checksums |
fc6c67c703be52d12c3c1d55b2aa0b28f776fbdc6109570296e0f9755c2d1bfd
|
| 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 18, 2026.
Transparency logRelease files / routernet-0.1.1-py3-none-any.whl
| Download URL | routernet-0.1.1-py3-none-any.whl |
|---|---|
| Size | 27.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
73458642e35381bfc69a1b0f604f4cbf88fc3f59bda8cf113af14de936346b3d
|
|
BLAKE2b-256 checksum How to use checksums |
d08935059438cdc8684f5b0601006f0af22e35264753ce82a63af53210d14faf
|
| 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 18, 2026.
Transparency log