Lightweight, model-agnostic hyperparameter tuning. Works standalone or alongside KANBoost.
Project description
Kantun
A lightweight, model-agnostic hyperparameter tuning library.
Built as a companion to KANBoost, but with zero
hard dependency on it — Kantun works with any estimator that follows a
scikit-learn-like fit/predict/predict_proba interface. Use it with
KANBoost, with RandomForestClassifier, with your own custom model —
your choice.
Why a separate package?
Not everyone using KANBoost needs hyperparameter search, and not everyone doing hyperparameter search needs KANBoost. Splitting them keeps each library's dependency footprint minimal and lets Kantun be useful on its own.
Install
pip install -r requirements.txt
pip install -e .
To also tune KANBoost models, install it separately:
pip install -e ../kanboost_project # local, or: pip install kanboost (once published to PyPI)
# repo: https://github.com/tuamah/kanboost
Quickstart
from kantun import KantunSearch
from kanboost import KANBoostClassifier
param_space = {
"n_estimators": [30, 60, 100],
"learning_rate": [0.1, 0.2, 0.3],
"kan_hidden": [3, 4, 6],
"kan_grid": [2, 3],
}
search = KantunSearch(
KANBoostClassifier,
param_space,
n_iter=10,
cv=3,
scoring="auc",
)
search.fit(X, y)
print(search.best_params_, search.best_score_)
best_model = search.best_estimator_ # ready to use
results_df = search.results_dataframe() # sorted leaderboard
Works with any sklearn-style estimator, not just KANBoost
from sklearn.ensemble import RandomForestClassifier
from kantun import KantunSearch
search = KantunSearch(
RandomForestClassifier,
{"n_estimators": [50, 100], "max_depth": [3, 5, None]},
n_iter=5, cv=3, scoring="f1",
use_eval_set=False, # RandomForestClassifier.fit() has no eval_set kwarg
)
search.fit(X, y)
How it decides whether to use early stopping
KantunSearch inspects the target model class's fit() signature. If
it finds an eval_set parameter (as KANBoost's estimators do), it
automatically passes eval_set=(X_val, y_val) on each fold so early
stopping kicks in during the search itself. You can override this with
use_eval_set=True/False explicitly.
Supported scoring
- Classification:
"auc"(default),"f1","accuracy" - Regression:
"neg_mse"(default),"neg_mae"
Search types
-
search_type="random"(default): samplesn_iterrandom combinations -
search_type="grid": tries every combination inparam_distributions -
search_type="halving": successive halving -- starts every candidate on a small, stratified subsample of each fold's training data (held-out validation data is always full and untouched), keeps the top1/halving_factorby score, and grows the training subsample byhalving_factoreach round until a round trains on the full data. Training-set size is the resource halved (not, say,n_estimators), since it's the only resource meaningful for any estimator -- kantun tunes arbitrary sklearn-compatible models, not just KANBoost. Useful when you have more candidates than you can afford to fully evaluate.search = KantunSearch( KANBoostClassifier, param_space, search_type="halving", n_iter=20, cv=3, halving_factor=3, min_resource=50, )
Speeding up an expensive search
Two independent knobs, useful together or separately, both aimed at the case kantun was built for: tuning an estimator that's slow to fit per combination (like KANBoost, ~10-20x a tree ensemble):
n_jobs: evaluate multiple param combos concurrently (threads, not processes -- safe for CUDA device selection, and PyTorch releases the GIL during tensor ops so real overlap still happens).search = KantunSearch(KANBoostClassifier, param_space, n_jobs=4)
prune=True: abandon a combo after its first CV fold if that fold's score already falls more thanprune_marginstandard deviations (of the current best combo's own fold spread) below the running best -- skips the remainingcv - 1folds for combos that are essentially never going to become the best. A pruned combo's single-fold score is recorded incv_results_("pruned": True) but never becomesbest_params_/best_score_. Off by default; the first combo evaluated is never pruned (there's nothing to compare against yet).search = KantunSearch(KANBoostClassifier, param_space, prune=True, prune_margin=1.0)
License
MIT — see LICENSE.
Project details
Release history Release notifications | RSS feed
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 kantun-0.0.3.tar.gz.
File metadata
- Download URL: kantun-0.0.3.tar.gz
- Upload date:
- Size: 14.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca12a856c24972e708fbccd3a2f03880b16c954d61d4a73a996091751cf0a856
|
|
| MD5 |
ff8f723543c603dc82a45f834b94f3f6
|
|
| BLAKE2b-256 |
83bbfb3a7127db25d1c368f6771b346a71edad27b8e84446934010e4383e6e3e
|
Provenance
The following attestation bundles were made for kantun-0.0.3.tar.gz:
Publisher:
publish.yml on tuamah/kantun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kantun-0.0.3.tar.gz -
Subject digest:
ca12a856c24972e708fbccd3a2f03880b16c954d61d4a73a996091751cf0a856 - Sigstore transparency entry: 2107507925
- Sigstore integration time:
-
Permalink:
tuamah/kantun@fcc14a371aabdf7be5bfc84ac5162cfefeb08cc2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/tuamah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fcc14a371aabdf7be5bfc84ac5162cfefeb08cc2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kantun-0.0.3-py3-none-any.whl.
File metadata
- Download URL: kantun-0.0.3-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a19fbeac48f12434207b0165bb3adce0cbee5d320d5c12afa6992df24ed2c952
|
|
| MD5 |
0eb4713678c69019ecc393f1af0caf03
|
|
| BLAKE2b-256 |
c58623efa23588023b577c39d3eb99fa2eb14a4aa395ec1ded14fc8f414827f2
|
Provenance
The following attestation bundles were made for kantun-0.0.3-py3-none-any.whl:
Publisher:
publish.yml on tuamah/kantun
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kantun-0.0.3-py3-none-any.whl -
Subject digest:
a19fbeac48f12434207b0165bb3adce0cbee5d320d5c12afa6992df24ed2c952 - Sigstore transparency entry: 2107508064
- Sigstore integration time:
-
Permalink:
tuamah/kantun@fcc14a371aabdf7be5bfc84ac5162cfefeb08cc2 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/tuamah
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fcc14a371aabdf7be5bfc84ac5162cfefeb08cc2 -
Trigger Event:
release
-
Statement type: