I have extracted a set of features for a classification task and I used the SVM classifier. How can I find the top
k predictive features and their discriminative power (chi square) value?
Here is a tutorial on the website of scikit-learn that shows you how to compute chi².
Copying from the mentioned website:
>>> from sklearn.datasets import load_iris >>> from sklearn.feature_selection import SelectKBest >>> from sklearn.feature_selection import chi2 >>> iris = load_iris() >>> X, y = iris.data, iris.target >>> X.shape (150, 4) >>> X_new = SelectKBest(chi2, k=2).fit_transform(X, y) >>> X_new.shape (150, 2)