# When used for feature selection, does the chi-squared test require the features to be nonnegative?

scikit-learn says chi squared test used for feature selection in classification problems and implemented by sklearn.feature_selection.chi2 requires the feature which it tests with the outcome to be nonnegative.

As I understand from Wikipedia, the chi squared independence test test independence between two discrete random variables with finite ranges from their joint samples. So the random variables can be categorical, positive, or nonnegative, as long as they are discrete and have finite ranges, i.e. we can create a contingency table from their joint samples.

So what features can the chi squared feature selection in scikit-learn apply to?

Thanks.

• Yes, it does. Events are non-negative, and squares of real numbers are non-negative. – Carl Feb 15 '18 at 23:19