swectral.combine_classifier#
- swectral.combine_classifier(trainable_processor, classifier, trainable_processor_label=None, classifier_label=None, preserve_train_state=False)[source]#
Combine trainable data preprocessing models with a classifier into a unified estimator that preserves component names.
This wrapper functions similarly to scikit-learn’s Pipeline but compatible with any transformer and classifier that follows scikit-learn’s method conventions.
- Parameters:
- trainable_processor
objectorlistofobject Data preprocessing model(s), any trainable data preprocessing, feature selection, or resampling model(s).
- classifier
object Classification model.
- trainable_processor_label
strorlistofstrorNone,optional Label(s) for the transformer(s). Defaults to model class names if not specified.
- classifier_label: str or None
Label for the classifier. Defaults to model class name if not specified.
- trainable_processor
- Returns:
objectCombined classification model.
- Return type:
Examples
Prepare models:
>>> from sklearn.feature_selection import SelectKBest, f_classif >>> from sklearn.preprocessing import StandardScaler >>> from sklearn.neighbors import KNeighborsClassifier >>> selector = SelectKBest(f_classif, k=5) >>> scaler = StandardScaler() >>> knn = KNeighborsClassifier(n_neighbors=3)
Without specifying model labels:
>>> combined_model = combine_classifier([scaler, selector], knn)
Specify model labels:
>>> combined_model = combine_classifier( ... [scaler, selector], ... knn, ... trainable_processor_label=['scaler', 'selector'], ... classifier_label='knn' ... )