ITMO_FS.filters.sparse.SPEC

class ITMO_FS.filters.sparse.SPEC(p, k=5, gamma=<function SPEC.<lambda>>, sigma=0.5, phi_type=1)

Performs the Spectral Feature Selection algorithm.

Parameters:
  • p (int) – Number of features to select.
  • k (int, optional) – Amount of clusters to find.
  • gamma (callable, optional) – An “increasing function that penalizes high frequency components”. Default is gamma(x) = x^2.
  • sigma (float, optional) – Parameter for the weighting scheme.
  • phi_type (int (1, 2 or 3), optional) – Type of feature ranking function to use.

Notes

For more details see this paper.

Examples

__init__(p, k=5, gamma=<function SPEC.<lambda>>, sigma=0.5, phi_type=1)

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

feature_ranking(W)

Calculate the SPEC score for a feature weight matrix.

Parameters:W (array-like, shape (n_features)) – Feature weight matrix.
Returns:indices – Indices of p selected features.
Return type:array-like, shape(p)
run(X, y=None)

Fits filter

Parameters:
  • X (numpy array, shape (n_samples, n_features)) – The training input samples.
  • y (numpy array, optional) – The target values. If present, label values are used to construct the similarity graph and the amount of classes overrides k.
Returns:

W – Feature weight matrix.

Return type:

array-like, shape (n_features)

Examples

>>> from ITMO_FS.filters.sparse import SPEC
>>> 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 = SPEC(p=5, k=2)
>>> weights = model.run(data, target)
>>> print(model.feature_ranking(weights))