This page

Citing

Please consider citing the scikit-learn.

9.15.3. sklearn.feature_selection.univariate_selection.chi2

sklearn.feature_selection.univariate_selection.chi2(X, y)

Compute χ² (chi-squared) statistic for each class/feature combination.

This transformer can be used to select the n_features features with the highest values for the χ² (chi-square) statistic from either boolean or multinomially distributed data (e.g., term counts in document classification) relative to the classes.

Recall that the χ² statistic measures dependence between stochastic variables, so a transformer based on this function “weeds out” the features that are the most likely to be independent of class and therefore irrelevant for classification.

Parameters :

X : {array-like, sparse matrix}, shape = [n_samples, n_features_in]

Sample vectors.

y : array-like, shape = n_samples

Target vector (class labels).