ITMO_FS.filters.univariate.chi2_measure¶
-
ITMO_FS.filters.univariate.chi2_measure(x, y)¶ Calculate the Chi-squared measure for each feature. Bigger values mean more important features. This measure works best with discrete features due to being based on statistics.
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_features,)
Return type: feature scores
See also
http()- //lkm.fri.uni-lj.si/xaigor/slo/clanki/ijcai95z.pdf
Example
>>> from ITMO_FS.filters.univariate import chi2_measure >>> from sklearn.preprocessing import KBinsDiscretizer >>> import numpy as np >>> 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]) >>> est = KBinsDiscretizer(n_bins=10, encode='ordinal') >>> x = est.fit_transform(x) >>> chi2_measure(x, y) array([ 1.875 , 0.83333333, 10. , 3.75 , 6.66666667])