Turn a component's JSON Schema into a searchable parameter space.
Every TuiML algorithm already publishes get_parameter_schema, a JSON Schema per constructor parameter. This module reads that schema and derives a ParameterDistribution from it, so a tuner can search any algorithm in the library without a hand-written grid.
The module is deliberately standalone: it depends only on the registry metadata and tuning, so RandomSearchCV and friends can use it directly, with or without automl.
>>> from tuiml.automl.search_space import search_space_for
>>> from tuiml.algorithms.trees import DecisionTreeClassifier
>>> space = search_space_for(DecisionTreeClassifier)
>>> sorted(space.param_distributions)
['criterion', 'max_depth', 'min_samples_leaf', 'min_samples_split']
>>> space.skipped_["random_state"]
'excluded: not a model-behaviour parameter'
Functions
Convert a parameter schema into ParameterDistribution specs.
Each parameter is mapped to one of the forms ParameterDistribution understands:
================================== ================================ Schema fragment Distribution spec ================================== ================================ {"enum": [...]} the list of enum values {"type": "boolean"} [True, False] {"type": "integer", min, max} (min, max, 'int') {"type": "number", min, max} (min, max) or (min, max, 'log') {"type": ["integer", "null"]} [None, level, level, ...] {"default": None, min, no max} [None, level, level, ...] ================================== ================================
A union with "null" keeps None as an explicit choice, since for parameters like max_depth "no limit" is a real setting rather than a missing value. A union of two or more concrete types (for example ["number", "string"] for a parameter that also accepts "auto") is skipped unless it carries an enum: there is no safe way to guess which arm the tuner should explore.
Parameters
schema
get_parameter_schema.
include
exclude
EXCLUDED_PARAMETERS.
Returns
distributions
ParameterDistribution.
skipped
>>> from tuiml.automl.search_space import schema_to_distribution
>>> schema = {
... "alpha": {"type": "number", "minimum": 0.0001, "maximum": 1.0},
... "fit_intercept": {"type": "boolean", "default": True},
... "n_jobs": {"type": "integer", "default": 1},
... }
>>> dists, skipped = schema_to_distribution(schema)
>>> dists["alpha"]
(0.0001, 1.0, 'log')
>>> dists["fit_intercept"]
[True, False]
>>> skipped["n_jobs"]
'excluded: not a model-behaviour parameter'
Build a searchable parameter space for one algorithm class.
get_parameter_schema, converts it with schema_to_distribution, and drops anything the constructor does not actually accept -- a schema occasionally documents a parameter that the current signature no longer takes, and sampling it would raise.Parameters
algorithm_cls
"RandomForestClassifier").
include
exclude
EXCLUDED_PARAMETERS.
Returns
space
space.skipped_ maps every parameter that was left out to the reason why, so an empty or surprising space can be debugged without re-deriving it.
>>> from tuiml.automl.search_space import search_space_for
>>> space = search_space_for("RandomForestClassifier")
>>> space.param_distributions["criterion"]
['gini', 'entropy']
>>> params = space.sample(random_state=0)
>>> sorted(params)
['bootstrap', 'criterion', 'max_depth', 'min_samples_leaf', 'min_samples_split', 'n_estimators', 'oob_score']
>>> space.skipped_["max_features"]
"ambiguous union type ['string', 'integer', 'number'] without an enum; no safe way to pick which arm to search"