I am asking a question very closely related to this one (same question as one of the answers).
My understanding is that chi2 test can only be used when features and the target are categorical variables, represented as binary. However, sklearn example has continuous data for features and target.
https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectKBest.html
>>> from sklearn.datasets import load_digits
>>> from sklearn.feature_selection import SelectKBest, chi2
>>> X, y = load_digits(return_X_y=True)
>>> X.shape
(1797, 64)
>>> X_new = SelectKBest(chi2, k=20).fit_transform(X, y)
>>> X_new.shape
(1797, 20)
I also tested this on a small toy example and feature selection looks to be giving reasonable results.
What is going on here? How does this work? My first thought is that the data gets binned under the hood, but I am still not clear how that would work.