SVM-Anova: SVM with univariate feature selection¶
This example shows how to perform univariate feature selection before running a SVC (support vector classifier) to improve the classification scores.
Import some data to play with
Create a feature-selection transform and an instance of SVM that we combine together to have an full-blown estimator
Plot the cross-validation score as a function of percentile of features
score_means = list() score_stds = list() percentiles = (1, 3, 6, 10, 15, 20, 30, 40, 60, 80, 100) for percentile in percentiles: clf.set_params(anova__percentile=percentile) # Compute cross-validation score using 1 CPU this_scores = cross_val_score(clf, X, y, n_jobs=1) score_means.append(this_scores.mean()) score_stds.append(this_scores.std()) plt.errorbar(percentiles, score_means, np.array(score_stds)) plt.title( 'Performance of the SVM-Anova varying the percentile of features selected') plt.xlabel('Percentile') plt.ylabel('Prediction rate') plt.axis('tight') plt.show()
Total running time of the script: ( 0 minutes 0.681 seconds)