0

我正在尝试为我的 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 个输出类;1 类和 0 类。这是我的输入文件。输入

4

1 回答 1

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}

于 2019-04-22T11:04:31.087 回答