swectral.factorial_model_chains#

swectral.factorial_model_chains(*step_trainable_processors, estimators, is_regression=True, preserve_train_state=False)[source]#

Combine trainable data preprocessing models of each step with estimators into chained models using a full-factorial approach.

Parameters:
step_trainable_processorstuple of (list of object, dict mapping str to object, or None)

Data preprocessing model instance of each step. Valid inputs for each element include:

  • sklearn-style transformers implementing fit and transform.

  • imblearn-style resamplers implementing fit_resample.

Customize trainable processor name using dictionary input as {custom_name : trainable_processor}.

estimatorslist of object or dict mapping str to object

Estimators for final step.

is_regressionbool

Set True if all estimators are regressors, set False if all estimators are classifiers.

Note: estimators cannot be a mix of regressors and classifiers.

Returns:
list of object

List of combined models.

Return type:

list[object]

Examples

Prepare models:

>>> from sklearn.feature_selection import SelectKBest, f_classif
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.neighbors import KNeighborsClassifier
>>> selector5 = SelectKBest(f_classif, k=5)
>>> selector10 = SelectKBest(f_classif, k=10)
>>> rf = RandomForestClassifier(n_estimators=10)
>>> knn = KNeighborsClassifier(n_neighbors=3)

Without specify labels for component models:

>>> models = factorial_transformer_chains(
...     [selector5, selector10],
...     estimators=[knn, rf],
...     is_regression=False
... )

Specify labels for component models:

>>> models = factorial_transformer_chains(
...     {'feat5': selector5, 'feat10': selector10},
...     estimators={'KNN': knn, 'RF': rf},
...     is_regression=False
... )