pythonpython-3.xmachine-learningsvmmlxtend

How to add filler feature values for 10 features?


I'm trying to add filler feature values for my SVM non-linear decision boundary. I got this error Column(s) [1 5 6 7 8] need to be accounted for in either feature_index or filler_feature_values.

Here's my code:

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()

I have 2 output classes; class 1 and class 0. Here's my input file. Input


Solution

  • You are plotting feature 0 against feature 9 (feature_index), and filling feature values 2, 3 and 4 (filler_feature_values). Nowhere are you specifying what to do with features 1, 5, 6, 7, 8 which is why you get the error. Adding these to the filler_feature_values / filler_feature_ranges should resolve this.

    {1:value, 2: value, 3:value, 4:value, 5:value, 6: value, 7:value, 8:value}