错误颜色的mglearn图

时间:2019-10-09 13:27:22

标签: python machine-learning plot colors

首先,我必须说我是Python的初学者,依此类推...因此,如果我的问题很愚蠢,请事先谅解!

我目前正在尝试学习一些有关机器学习的知识,尤其是使用mglearn。我想进行回归分类,为此我使用了线性SVM。

我正在尝试此脚本:

import mglearn
import matplotlib.pyplot as plt
import numpy as np
from sklearn.datasets import make_blobs
X, y = make_blobs(random_state=42)
from sklearn.svm import LinearSVC
linear_svm = LinearSVC().fit(X, y)
mglearn.plots.plot_2d_classification(linear_svm, X, fill=True, alpha=.7)

mglearn.discrete_scatter(X[:, 0], X[:, 1], y)
line = np.linspace(-15, 15)
for coef, intercept, color in zip(linear_svm.coef_, linear_svm.intercept_, ['b', 'r', 'g']):
    plt.plot(line, -(line * coef[0] + intercept) / coef[1])

plt.ylim(-10, 15)
plt.xlim(-10, 8)
plt.xlabel("Feature 0")
plt.ylabel("Feature 1")
plt.legend(['Class 0', 'Class 1', 'Class 2', 'Line class 0', 'Line class 1', 'Line class 2'], loc=(1.01, 0.3))

我的问题是,当我这样做时,根据阅读的图图,这些点和这些点的“背景”应该是相同的颜色。正如您在图片上看到的,我具有链接,绿色点在红色背景上,红色点在绿色背景上。

有什么想法吗?

The plot with the wrong colors...

感谢人们:)

0 个答案:

没有答案