A filter method scores each feature on its own, before any model is trained. For a categorical feature, the chi-square statistic compares how often each (category, label) pair actually occurs with how often it would occur if the feature and the label were independent.
Implement chi2_statistic(x, y).
x and y are one-dimensional integer arrays of the same length (category and label).O with one row per distinct category of x and one column per distinct label of y.E[i, j] = row_total[i] * col_total[j] / N.sum((O - E) ** 2 / E) as a Python float.x and y differ in length, or are empty, raise ValueError.np.unique(..., return_inverse=True) gives you the row and column index of every sample, and np.add.at fills the table.
No results yet
Run your code to check it against the examples, or submit to run every test.