plot_sequential_feature_selection:可视化 SequentialFeatureSelector 选择的特征子集性能

一个 matplotlib 实用函数,用于可视化 feature_selection.SequentialFeatureSelector 的结果。

from mlxtend.plotting import plot_sequential_feature_selection

概述

有关顺序特征选择的更多信息,请参阅 feature_selection.SequentialFeatureSelector

示例 1 - 绘制 SequentialFeatureSelector 的结果

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',
                figsize=(6, 4))

plt.ylim([0.8, 1])
plt.title('Sequential Forward Selection (w. StdDev)')
plt.grid()
plt.show()

png

API

plot_sequential_feature_selection(metric_dict, figsize=None, kind='std_dev', color='blue', bcolor='steelblue', marker='o', alpha=0.2, ylabel='Performance', confidence_interval=0.95)

绘制特征选择结果。

参数

  • metric_dict : mlxtend.SequentialFeatureSelector.get_metric_dict() 对象

  • figsize : 元组 (默认值: None)

    图形的高度和宽度

  • kind : str (默认值: "std_dev")

    误差条或置信区间的类型,可选值 {'std_dev', 'std_err', 'ci', None}。

  • color : str (默认值: "blue")

    折线图的颜色(接受任何 matplotlib 颜色名称)

  • bcolor : str (默认值: "steelblue")。

    误差条 / 置信区间的颜色(接受任何 matplotlib 颜色名称)。

  • marker : str (默认值: "o")

    折线图的标记(接受任何 matplotlib 标记名称)。

  • alpha : 介于 [0, 1] 之间的浮点数 (默认值: 0.2)

    误差条 / 置信区间的透明度。

  • ylabel : str (默认值: "Performance")

    Y 轴标签。

  • confidence_interval : 浮点数 (默认值: 0.95)

    如果 kind='ci',则为置信水平。

返回值

  • fig : matplotlib.pyplot.figure() 对象

示例

有关使用示例,请参阅 https://mlxtend.cn/mlxtend/user_guide/plotting/plot_sequential_feature_selection/

ython