Skip to main content

SLATE: a tiny, interpretable, scikit-learn-compatible additive threshold classifier.

Project description

tinyslate

SLATESparse Lightweight Additive Threshold Ensemble — is a tiny, fully interpretable, scikit-learn-compatible classifier.

Install

pip install tiny-slate

Note the import name keeps no hyphen (Python identifiers cannot contain one):

from tinyslate import SlateClassifier

Quick start

from tinyslate import SlateClassifier
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)

clf = SlateClassifier(budget=32).fit(X_train, y_train)

print("accuracy:", clf.score(X_test, y_test))
print("probabilities:", clf.predict_proba(X_test[:3]))
print("atoms used:", clf.n_atoms_)
print("footprint (bytes):", clf.memory_bytes_)

Because it follows the scikit-learn estimator API, it drops straight into pipelines and model selection:

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import GridSearchCV

pipe = make_pipeline(StandardScaler(), SlateClassifier())
grid = GridSearchCV(
    pipe,
    {"slateclassifier__budget": [16, 32, 64],
     "slateclassifier__learning_rate": [0.3, 0.5]},
    cv=3,
)
grid.fit(X_train, y_train)

Why SLATE

  • Interpretable by construction — a prediction is a sum of signed rule contributions; there is no post-hoc approximation.
  • Tiny and fixed-size — storage is budget * (1 threshold + n_classes coefficients) plus n_classes intercepts, independent of dataset size.
  • Shared atoms — one rule pool serves every class, so a K-class model is far smaller than K independent one-vs-rest scorers.
  • Standard APIfit, predict, predict_proba, decision_function, score, explain, get_params/set_params; works with Pipeline, GridSearchCV, cross_val_score, and clone.

Parameters

Parameter Default Meaning
budget 64 Max number of shared threshold atoms (capacity / sparsity).
n_bins 32 Quantile bins proposed per feature for candidate thresholds.
max_iter None Boosting iterations; Nonemin(1200, 6*budget).
learning_rate 0.5 Shrinkage on each Newton update.
l2 2.0 Ridge regularization on the Hessian (> 0).
l1 1e-3 Lasso penalty in the corrective pass (prunes atoms).
corrective_every 5 Run a corrective refit every N iterations.
corrective_passes 2 Coordinate sweeps per corrective refit.
tol 1e-9 Minimum Newton gain to keep adding atoms.
random_state 0 Accepted for API compatibility; fitting is deterministic.

Fitted attributes

classes_, n_features_in_, intercept_, atom_feature_, atom_threshold_, atom_coef_, n_atoms_, plus the introspection helpers n_parameters_, memory_bytes_, and footprint_bytes().

Inspecting the rules

Because the model is additive, every prediction decomposes exactly into an intercept plus the contribution of each rule that fired. Use explain:

clf = SlateClassifier(budget=16).fit(X_train, y_train)

for e in clf.explain(X_test[:1]):
    print("predicted:", e["predicted_class"], "  score:", round(e["score"], 3))
    print("intercept:", round(e["intercept"], 3))
    for a in e["atoms"]:                       # sorted by |contribution|
        print(f"  feature[{a['feature']}] <= {a['threshold']:.3f}"
              f"  ->  {a['contribution']:+.3f}")

intercept + sum(contributions) equals the class score exactly, so the explanation is faithful, not an approximation. Pass class_index=k to decompose the score of a specific class instead of the predicted one. The raw rule pool is also available directly via atom_feature_, atom_threshold_, and atom_coef_.

Requirements

  • Python ≥ 3.9
  • numpy ≥ 1.22
  • scikit-learn ≥ 1.0

License

MIT © Saikiran Gogineni

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

tiny_slate-0.1.0.tar.gz (11.1 kB view details)

Uploaded Source

Built Distribution

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

tiny_slate-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tiny_slate-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for tiny_slate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5e2783085b16a9ea11e25cb3623a37ef7bf55d5aa641088153d83a72ef33eb48
MD5 bfa92bfc53c2565b44f179cb68d0bbb1
BLAKE2b-256 906d62df41195607027fe2247f65aea684b02f7be0e4748be4e6eb3f7ebb32e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tiny_slate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for tiny_slate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7dc0a912ce2f9371a0ccb86eba44db4671c7504fef2fdfa3b6653b9e67ca5be7
MD5 b66902774d4fa583302eff470ae6de58
BLAKE2b-256 6e30e6f5f47a231e3dd3dfd1ba731b4bc1b0a32559dfdd0576becceb598d75a8

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