我正在尝试为我的SVM非线性决策边界添加填充特征值。我收到此错误Column(s) [1 5 6 7 8] need to be accounted for in either feature_index or filler_feature_values
。
这是我的代码:
import numpy as np
import pandas as pd
from sklearn import svm
from mlxtend.plotting import plot_decision_regions
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
autism = pd.read_csv('10-features-uns.csv')
X = autism.drop(['TARGET'], axis = 1)
y = autism['TARGET']
x_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.30, random_state=1)
clf = svm.SVC(C=1.0, kernel='rbf', gamma=0.8)
clf.fit(X_test.values, y_test.values)
value=1.5
width=0.75
# Plot Decision Region using mlxtend's awesome plotting function
plot_decision_regions(X=X_test.values,
y=y_test.values,
clf=clf,
feature_index=[0,9],
filler_feature_values={2: value, 3:value, 4:value},
filler_feature_ranges={2: width, 3: width, 4: width},
legend=2)
# Update plot object with X/Y axis labels and Figure Title
plt.xlabel(X_test.columns[0], size=14)
plt.ylabel(X_test.columns[1], size=14)
plt.title('SVM Decision Region Boundary', size=16)
plt.show()
我有2个输出类别; class 1和class0。这是我的输入文件。 Input
答案 0 :(得分:0)
您正在针对特征9(feature_index
)绘制特征0,并填充特征值2、3和4(filler_feature_values
)。您无处指定如何处理功能1、5、6、7、8,这就是为什么会出现错误的原因。将它们添加到filler_feature_values
/ filler_feature_ranges
应该可以解决此问题。
{1:value, 2: value, 3:value, 4:value, 5:value, 6: value, 7:value, 8:value}