我试图绘制支持向量机的决策边界,将癌症和非癌症区分开来。然而,它展示的情节与我想要的相去甚远。我希望它看起来像这样:
import numpy as np
import pandas as pd
from sklearn import svm
from mlxtend.plotting import plot_decision_regions
import matplotlib.pyplot as plt
autism = pd.read_csv('predictions.csv')
# Fit Support Vector Machine Classifier
X = autism[['TARGET','Predictions']]
y = autism['Predictions']
clf = svm.SVC(C=1.0, kernel='rbf', gamma=0.8)
clf.fit(X.values, y.values)
# Plot Decision Region using mlxtend's awesome plotting function
plot_decision_regions(X=X.values,
y=y.values,
clf=clf,
legend=2)
# Update plot object with X/Y axis labels and Figure Title
plt.xlabel(X.columns[0], size=14)
plt.ylabel(X.columns[1], size=14)
plt.title('SVM Decision Region Boundary', size=16)
plt.show()
但我有一个奇怪的情节:
您可以在这里找到csv文件predictions.csv
你听起来有点困惑。。。在
您的
predictions.csv
看起来像:而且,正如我猜列名所暗示的那样,它包含了基本真理(
TARGET
)和一些(?)的Predictions
模型已经运行。在鉴于此,您在发布的代码中所做的工作完全没有意义:您将这两个列作为您的
X
中的功能来预测您的y
,这是。。。正好是这些列中的一个(Predictions
),已经包含在您的X
中。。。在你的图看起来很“奇怪”,因为你绘制的是不是你的数据点,你在这里显示的}数据是适合你的分类器的数据。在
X
和{我更困惑的是,在你的链接回购中,你的脚本中确实有正确的程序:
^{pr2}$也就是说,从
10-features-uns.csv
中读取你的特性和标签,当然,不是来自predictions.csv
,就像你在这里莫名其妙地试图做的那样。。。在相关问题 更多 >
编程相关推荐