classifierpromax.FeatureSelector

Functions

FeatureSelector(preprocessor, trained_models, X_train, ...)

Selects features for multiple classification models using RFE or Pearson methods.

Module Contents

classifierpromax.FeatureSelector.FeatureSelector(preprocessor, trained_models, X_train, y_train, method='RFE', n_features_to_select=None)[source]

Selects features for multiple classification models using RFE or Pearson methods.

Parameters:

preprocessorsklearn.pipeline.Pipeline or Transformer

Preprocessing pipeline to include in the final pipeline.

trained_modelsdict

A dictionary containing the names and corresponding trained best classification models. Keys are model names, and values are trained pipelines.

X_trainarray-like or DataFrame

Training feature set.

y_trainarray-like or Series

Training target labels.

methodstr, optional

Feature selection method. Defaults to ‘RFE’. Can be one of {‘RFE’, ‘Pearson’}.

n_features_to_selectint, optional

The number of features to select. Required for both ‘RFE’ and ‘Pearson’ methods. Defaults to None.

Returns:

feature_selected_modelsdict

A dictionary containing the feature-selected models. Keys are model names, and values are pipelines with feature selection applied.

Raises:

ValueError

If n_features_to_select is not provided or an invalid method is specified.

Examples:

>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.preprocessing import StandardScaler
>>> from sklearn.datasets import make_classification
>>> X_train, y_train = make_classification(n_samples=100, n_features=10, random_state=42)
>>> trained_models = {
...     'RandomForest': make_pipeline(StandardScaler(), RandomForestClassifier())
... }
>>> preprocessor = StandardScaler()
>>> feature_selected_models = FeatureSelector(
...     preprocessor, trained_models, X_train, y_train, method='RFE', n_features_to_select=5
... )
>>> print(feature_selected_models.keys())
dict_keys(['RandomForest'])