ITMO_FS.hybrid.FilterWrapperHybrid¶
-
class
ITMO_FS.hybrid.FilterWrapperHybrid(filter_, wrapper)¶ Perform the filter + wrapper hybrid algorithm by first running the filter algorithm on the full dataset, leaving the selected features and running the wrapper algorithm on the cut dataset.
Parameters: - filter (object) – A feature selection model that should have a fit(X, y) method and a selected_features_ attribute available after fitting.
- wrapper (object) – A feature selection model that should have a fit(X, y) method, selected_features_ and best_score_ attributes available after fitting and a predict(X) method.
Notes
This class doesn’t require the first algorithm to be a filter (the only requirements are a fit(X, y) method and a selected_features_ attribute) but it is recommended to use a fast algorithm first to remove a lot of unnecessary features before processing the resulting dataset with a more time-consuming algorithm (e.g. a wrapper).
Examples
>>> import numpy as np >>> from sklearn.linear_model import LogisticRegression >>> from ITMO_FS.wrappers.deterministic import BackwardSelection >>> from ITMO_FS.filters.univariate import UnivariateFilter >>> from ITMO_FS.hybrid import FilterWrapperHybrid >>> from sklearn.datasets import make_classification >>> dataset = make_classification(n_samples=100, n_features=20, ... n_informative=5, n_redundant=0, shuffle=False, random_state=42) >>> x, y = np.array(dataset[0]), np.array(dataset[1]) >>> filter_ = UnivariateFilter('FRatio', ("K best", 10)) >>> wrapper = BackwardSelection(LogisticRegression(), 5, measure='f1_macro') >>> model = FilterWrapperHybrid(filter_, wrapper).fit(x, y) >>> model.selected_features_ array([ 1, 3, 4, 10, 7], dtype=int64)
-
__init__(filter_, wrapper)¶ Initialize self. See help(type(self)) for accurate signature.
-
fit(X, y=None, **fit_params)¶ Fit the algorithm.
Parameters: - X (array-like, shape (n_samples, n_features)) – The training input samples.
- y (array-like, shape (n_samples,), optional) – The class labels.
- fit_params (dict, optional) – Additional parameters to pass to underlying _fit function.
Returns: Return type: Self, i.e. the transformer object.
-
fit_transform(X, y=None, **fit_params)¶ Fit to data, then transform it.
Fits transformer to X and y with optional parameters fit_params and returns a transformed version of X.
Parameters: - X ({array-like, sparse matrix, dataframe} of shape (n_samples, n_features)) –
- y (ndarray of shape (n_samples,), default=None) – Target values.
- **fit_params (dict) – Additional fit parameters.
Returns: X_new – Transformed array.
Return type: ndarray array of shape (n_samples, n_features_new)
-
get_params(deep=True)¶ Get parameters for this estimator.
Parameters: deep (bool, default=True) – If True, will return the parameters for this estimator and contained subobjects that are estimators. Returns: params – Parameter names mapped to their values. Return type: mapping of string to any
-
predict(X)¶ Predict class labels for the input data.
Parameters: X (array-like, shape (n_samples, n_features)) – The input samples. Returns: array-like, shape (n_samples,) Return type: class labels
-
set_params(**params)¶ Set the parameters of this estimator.
The method works on simple estimators as well as on nested objects (such as pipelines). The latter have parameters of the form
<component>__<parameter>so that it’s possible to update each component of a nested object.Parameters: **params (dict) – Estimator parameters. Returns: self – Estimator instance. Return type: object
-
transform(X)¶ Transform given data by slicing it with selected features.
Parameters: X (array-like, shape (n_samples, n_features)) – The training input samples. Returns: Return type: Transformed 2D numpy array