ITMO_FS.ensembles.measure_based.WeightBased

class ITMO_FS.ensembles.measure_based.WeightBased(filters, cutting_rule=('K best', 2), fusion_function=<function weight_fusion>, weights=None)

Weight-based filter ensemble. The ensemble first computes all filter scores for the dataset and then aggregates them using a selected fusion function.

Parameters:
  • filters (collection) – Collection of filter objects. Filters should have a fit(X, y) method and a feature_scores_ field that contains scores for all features.
  • cutting_rule (string or callable) – A cutting rule name defined in GLOB_CR or a callable with signature cutting_rule (features), which should return a list features ranked by some rule.
  • fusion_function (callable) – A function with signature (filter_scores (array-like, shape (n_filters, n_features)), weights (array-like, shape (n_filters,))) that should return the aggregated weights for all features.
  • weights (array-like) – An array of shape (n_filters,) defining the weights for input filters.

Examples

>>> from ITMO_FS.ensembles import WeightBased
>>> from ITMO_FS.filters.univariate import UnivariateFilter
>>> import numpy as np
>>> filters = [UnivariateFilter('GiniIndex'),
... UnivariateFilter('FechnerCorr'),
... UnivariateFilter('SpearmanCorr'),
... UnivariateFilter('PearsonCorr')]
>>> x = np.array([[3, 3, 3, 2, 2], [3, 3, 1, 2, 3], [1, 3, 5, 1, 1],
... [3, 1, 4, 3, 1], [3, 1, 2, 3, 1]])
>>> y = np.array([1, 3, 2, 1, 2])
>>> wb = WeightBased(filters, ("K best", 2)).fit(x, y)
>>> wb.selected_features_
array([4, 1], dtype=int64)
__init__(filters, cutting_rule=('K best', 2), fusion_function=<function weight_fusion>, weights=None)

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
get_scores(X, y)

Return the normalized feature scores for all filters.

Parameters:
  • X (array-like, shape (n_samples, n_features)) – The training input samples.
  • y (array-like, shape (n_samples,)) – The target values.
Returns:

array-like, shape (n_filters, n_features)

Return type:

feature scores

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