classifierpromax.FeatureSelector ================================ .. py:module:: classifierpromax.FeatureSelector Functions --------- .. autoapisummary:: classifierpromax.FeatureSelector.FeatureSelector Module Contents --------------- .. py:function:: FeatureSelector(preprocessor, trained_models, X_train, y_train, method='RFE', n_features_to_select=None) Selects features for multiple classification models using RFE or Pearson methods. Parameters: ----------- preprocessor : sklearn.pipeline.Pipeline or Transformer Preprocessing pipeline to include in the final pipeline. trained_models : dict A dictionary containing the names and corresponding trained best classification models. Keys are model names, and values are trained pipelines. X_train : array-like or DataFrame Training feature set. y_train : array-like or Series Training target labels. method : str, optional Feature selection method. Defaults to 'RFE'. Can be one of {'RFE', 'Pearson'}. n_features_to_select : int, optional The number of features to select. Required for both 'RFE' and 'Pearson' methods. Defaults to None. Returns: -------- feature_selected_models : dict 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'])