3

I am trying to use scikit-learn svc model on iris dataset. I need to use four features (sepal length/width, petal length/width) and all three classes(setosa, versicolor, virginica) to train data. Then I need to visualize results, presenting only two features on 2D graph. Problem that I am having is that my decision boundaries look wrong, and one subset of samples is missing (samples classified in one of the classes).

I followed Example 7 from mlxtend "plot_decision_regions":

http://rasbt.github.io/mlxtend/user_guide/plotting/plot_decision_regions/#example-7-decision-regions-with-more-than-two-training-features

I played with values of "value" and "width", but without much success. I also tried changing "zoom_factor" to lower values to check if maybe my plot is too much zoomed in.

iris = datasets.load_iris()
X = iris.data[:, [0,1,2,3]]
y = iris.target

# Training a classifier
svm = SVC(gamma='auto')
svm.fit(X, y)

# Plotting decision regions
fig, ax = plt.subplots()
# Decision region for feature 3 = 1.5
value = 1.5
# Plot training sample with feature 3 = 1.5 +/- 0.75
width = 0.75
plot_decision_regions(X, y, clf=svm,
                      filler_feature_values={2: value, 3: value},
                      filler_feature_ranges={2: width, 3: width},
                      legend=2, ax=ax,
                      zoom_factor=0.5)
ax.set_xlabel('Feature 1')
ax.set_ylabel('Feature 2')
ax.set_title('Feature 3 = {}'.format(value))

# Adding axes annotations
fig.suptitle('SVM on make_blobs')
plt.show()

When I try with all four features, I only get decision boundaries with no samples shown. With three features, only one set of samples is shown, properly classified with class 0. With two features, it shows all three sets of samples, properly classified among three classes.

DenR
  • 33
  • 5

0 Answers0