ITMO_FS.wrappers.deterministic.BackwardSelection

class ITMO_FS.wrappers.deterministic.BackwardSelection(estimator, n_features, measure)

Backward Selection removes one feature at a time until the number of features to be removed is reached. On each step, the best n-1 features out of n are chosen (according to some estimator metric) and the last one is removed.

Parameters:
  • estimator (object) – A supervised learning estimator with a fit method.
  • n_features (int) – Number of features to be removed.
  • measure (string or callable) – A standard estimator metric (e.g. ‘f1’ or ‘roc_auc’) or a callable object / function with signature measure(estimator, X, y) which should return only a single value.

Examples

__init__(estimator, n_features, measure)

Initialize self. See help(type(self)) for accurate signature.

fit(X, y, cv=3)

Fits wrapper.

Parameters:
  • X (array-like, shape (n_samples,n_features)) – The training input samples.
  • y (array-like, shape (n_samples,)) – The target values.
  • cv (int) – Number of folds in cross-validation.
Returns:

Return type:

None

Examples

>>> from ITMO_FS.wrappers import BackwardSelection
>>> from sklearn.linear_model import LogisticRegression
>>> from sklearn.datasets import make_classification
>>> import numpy as np
>>> dataset = make_classification(n_samples=100, n_features=20, n_informative=4, n_redundant=0, shuffle=False)
>>> data, target = np.array(dataset[0]), np.array(dataset[1])
>>> model = BackwardSelection(LogisticRegression(), 15, 'f1_macro')
>>> model.fit(data, target)
>>> print(model.selected_features)