ANOVA F-value For Feature Selection

20 Dec 2017

If the features are categorical, calculate a chi-square ($\chi^{2}$) statistic between each feature and the target vector. However, if the features are quantitative, compute the ANOVA F-value between each feature and the target vector.

The F-value scores examine if, when we group the numerical feature by the target vector, the means for each group are significantly different.

Load Data

Select Features With Best ANOVA F-Values

# Create an SelectKBest object to select features with two best ANOVA F-Valuesfvalue_selector=SelectKBest(f_classif,k=2)# Apply the SelectKBest object to the features and targetX_kbest=fvalue_selector.fit_transform(X,y)

View Results

# Show resultsprint('Original number of features:',X.shape[1])print('Reduced number of features:',X_kbest.shape[1])