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_processors
tupleof(listofobject,dictmappingstrtoobject,orNone) 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}.
- estimators
listofobjectordictmappingstrtoobject 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.
- step_trainable_processors
- Returns:
- Return type:
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 ... )