chi2
- sklearn.feature_selection.chi2(X, y)
Compute chi-squared stats between each non-negative feature and class.
This score can be used to select the
n_featuresfeatures with the highest values for the test chi-squared statistic from X, which must contain only non-negative integer feature values such as booleans or frequencies (e.g., term counts in document classification), relative to the classes.If some of your features are continuous, you need to bin them, for example by using
KBinsDiscretizer.Recall that the chi-square test measures dependence between stochastic variables, so using this function “weeds out” the features that are the most likely to be independent of class and therefore irrelevant for classification.