scikit-learn bridge for TuiML.
Importing this package registers the wrapped scikit-learn estimators into the TuiML hub under sklearn. keys, so they never collide with the native TuiML algorithms of the same name.
The wrapper modules mirror TuiML's own taxonomy, linear, svm, trees, ensemble, bayesian, neighbors, neural, clustering, anomaly, plus preprocessing/ and features/: so a wrapped estimator sits in the same place as its native counterpart. The wrapper classes are driven by the spec rows in specs; keep a module's classes and its spec rows in sync when editing either.
TuiML is native-first: its own algorithms are the primary implementations, and estimators are addressed by their namespaced hub key.
scikit-learn is an optional dependency:
pip install 'tuiml[sklearn]' # or: uv pip install 'tuiml[sklearn]'
If it is not installed, importing this package still succeeds (the wrapper classes are defined), but instantiating a wrapper raises a clear ImportError pointing at pip install tuiml[sklearn].
There are two ways to reach a wrapped estimator, and they are equivalent.
1. Import the class and use it like any TuiML algorithm, fit /
predict / predict_proba for models, fit_transform for
transformers. Constructor keywords are passed straight through to
scikit-learn:
>>> from tuiml.datasets import load_iris
>>> from tuiml.sklearn import RandomForestClassifier
>>> data = load_iris()
>>> model = RandomForestClassifier(n_estimators=50, random_state=0)
>>> model.fit(data.X, data.y).predict(data.X[:5]).tolist()
[0, 0, 0, 0, 0]
>>> model.predict_proba(data.X[:1]).shape
(1, 3)
2. Name it in a spec, as "sklearn.<ClassName>". This is the form
train takes, and the form an agent uses over MCP. Wrappers can
appear as the model or as pipeline steps, mixed freely with native components:
>>> import tuiml
>>> import tuiml.sklearn # registers the sklearn.* keys
>>> model = tuiml.train({
... "model": {"name": "sklearn.LogisticRegression",
... "params": {"max_iter": 500}},
... "data": {"source": "iris", "target": "class"},
... "pipeline": [{"name": "sklearn.StandardScaler"},
... {"name": "sklearn.SelectKBest", "params": {"k": 3}}],
... "evaluation": {"cv": 5, "metrics": ["accuracy_score"]},
... })
>>> round(model.metrics_["cv_accuracy_score_mean"], 2)
0.96
Names collide on purpose: sklearn.RandomForestClassifier and the native
RandomForestClassifier are different algorithms, and the prefix is what
picks one. Benchmarking the two against each other is the point:
>>> from tuiml import Benchmark
>>> import tuiml.sklearn
>>> bench = Benchmark(
... models=[{"name": "RandomForestClassifier"},
... {"name": "sklearn.RandomForestClassifier"}],
... datasets=[{"source": "iris"}],
... random_seed=0,
... )
>>> sorted(bench.run().scores_["model"].unique())
['RandomForestClassifier', 'sklearn.RandomForestClassifier']
Every wrapper reports its own parameters, derived from the scikit-learn actually installed, so the list is never stale:
>>> from tuiml.sklearn import SVC >>> sorted(SVC.get_parameter_schema())[:4] ['C', 'break_ties', 'cache_size', 'class_weight']
A parameter scikit-learn does not accept is rejected at fit time with the valid names listed, rather than being silently ignored.
Raw scikit-learn estimator objects are not accepted by train or Benchmark: to reach an estimator that is not yet wrapped, add a row to specs rather than passing an instance.
A handful of wrappers are renamed to avoid clashing with a native TuiML class of the same name, e.g. scikit-learn's PCA is exported as PCAExtractor. dir(tuiml.sklearn) lists the exported names.
scikit-learn anomaly wrappers....
scikit-learn bayesian wrappers....
scikit-learn clustering wrappers....
scikit-learn ensemble wrappers....
scikit-learn linear wrappers....
scikit-learn neighbors wrappers....
scikit-learn neural wrappers....
Declarative table of every wrapped scikit-learn estimator....
scikit-learn svm wrappers....
scikit-learn trees wrappers....