绘制决策边界

时间:2019-10-25 07:01:13

标签: python matplotlib plot scikit-learn mlxtend

我想要达到这样的结果: enter image description here

我真的很喜欢这种样式,决策区域的alpha位置低一点,坐标系具有这种样式。

目前,我的结果如下所示: enter image description here

这还不错,但我想更进一步了解榜样... 代码:

import matplotlib.pyplot as plt
from sklearn import svm
from sklearn.datasets import make_circles
import matplotlib.cm as cm
import matplotlib as mpl
from mlxtend.plotting import plot_decision_regions



colors = [(1.0, 0.6, 0.0), "white","blue"]
cm.register_cmap(cmap=mpl.colors.LinearSegmentedColormap.from_list("owb", colors).reversed())
cm.register_cmap(cmap=mpl.colors.LinearSegmentedColormap.from_list("owb", colors))

# we create 40 separable points
X, y = make_circles(n_samples=100, noise=0.04, factor=0.5)

# fit the model, don't regularize for illustration purposes
clf = svm.SVC(kernel='rbf')
clf.fit(X, y)


from mpl_toolkits.axes_grid.axislines import SubplotZero
fig = plt.figure(1)
ax1 = SubplotZero(fig, 111)
fig.add_subplot(ax1)
plt.xticks([-2,-1,0,1,2])
plt.yticks([-2,-1,0,1,2])
for direction in ["xzero", "yzero"]:
        ax1.axis[direction].set_axisline_style("-|>")
        ax1.axis[direction].set_visible(True)

for direction in ["left", "right", "bottom", "top"]:
        ax1.axis[direction].set_visible(False)


scatter_kwargs = {'s': 60, 'edgecolor': None, 'alpha': 0.7}
contourf_kwargs = {'alpha': 0.2}
# scatter_highlight_kwargs = {'s': 80, 'label': 'Test data', 'alpha': 0.7}

plot_decision_regions(X, y, clf=clf,markers="o", scatter_kwargs=scatter_kwargs,
                      contourf_kwargs=contourf_kwargs, colors='#ff7f0e,#1f77b4')

plt.show()

所以我对此感到满意,谢谢@Paul

仍然存在的问题 另一件事:如何绘制此图: enter image description here 我想到了多个线性决策边界,但没有找到实现我想要的方法的方法。

0 个答案:

没有答案
相关问题