I generate two columns of length 343180 with random integer values between 0 and 290 and run sklearn's chi2-test of dependence. One would expect that the null hypothesis (independence) is accepted with a high probability, but actually I get a test score of approx. 15423 and a p-value of 0.
import numpy as np
from sklearn.feature_selection import chi2
X = np.transpose([[np.random.randint(0, 291) for i in range(0, 343180)]])
y = np.asarray([np.random.randint(0, 291) for i in range(0, 343180)])
print(X.shape)
# output: (34318, 1)
print(y.shape)
# output: (34318,)
chi2(X, y)
# output: (array([15423.73497325]), array([0.]))
# which means: p-value = 0.
Does this has to do with the limits of pseudo random number generation? Or do I misunderstand the concept of a chi2-test? Does the chi2-test, as implemented in sklearn, expect a certain type of distribution of the tested features, and not just an arbitrary discrete distribution?