#!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('matplotlib', 'inline') # # Plot Sequential Feature Selection # A matplotlib utility function for visualizing results from [`feature_selection.SequentialFeatureSelector`](`../feature_selection/SequentialFeatureSelector.md`). # > from mlxtend.plotting import plot_sequential_feature_selection # # Overview # for more information on sequential feature selection, please see [`feature_selection.SequentialFeatureSelector`](`../feature_selection/SequentialFeatureSelector.md`). # ## Example 1 - Plotting the results from SequentialFeatureSelector # In[2]: from mlxtend.plotting import plot_sequential_feature_selection as plot_sfs from mlxtend.feature_selection import SequentialFeatureSelector as SFS import matplotlib.pyplot as plt from sklearn.neighbors import KNeighborsClassifier from sklearn.datasets import load_iris iris = load_iris() X = iris.data y = iris.target knn = KNeighborsClassifier(n_neighbors=4) sfs = SFS(knn, k_features=4, forward=True, floating=False, scoring='accuracy', cv=5) sfs = sfs.fit(X, y) fig1 = plot_sfs(sfs.get_metric_dict(), kind='std_dev') plt.ylim([0.8, 1]) plt.title('Sequential Forward Selection (w. StdDev)') plt.grid() plt.show() # # API # In[1]: with open('../../api_modules/mlxtend.plotting/plot_sequential_feature_selection.md', 'r') as f: s = f.read() print(s)