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_processorobject or list of object

Data preprocessing model(s), any trainable data preprocessing, feature selection, or resampling model(s).

classifierobject

Classification model.

trainable_processor_labelstr or list of str or None, 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.

Returns:
object

Combined classification model.

Return type:

object

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'
... )