Skip to main content

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): samples n_iter random combinations
  • search_type="grid": tries every combination in param_distributions

License

MIT — see LICENSE.

Project details


Download files

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

Source Distribution

kantun-0.0.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

kantun-0.0.2-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file kantun-0.0.2.tar.gz.

File metadata

  • Download URL: kantun-0.0.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for kantun-0.0.2.tar.gz
Algorithm Hash digest
SHA256 00cf7ca3ec6f223cfb349d9aa1ccf9de42be26d2dce11008f9e223947abec7ab
MD5 18de170e09ff379edf3f9441a8731622
BLAKE2b-256 4589413568c58a55b3da7927137a43907501a4ed84f4e78e4ff6775893164b39

See more details on using hashes here.

File details

Details for the file kantun-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: kantun-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for kantun-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 095719d8b983c2b330c313db56e51f332c9c431e245e724f5b7cad49f8b450af
MD5 d4f4a91e08dd6977e8287ee56a2d294f
BLAKE2b-256 d37c8a8f7505ab800ded3ecc6f922d730b612784598b3e66978394d7be1c0242

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page