I made a SVM plot from the Iris-dataset by using matplotlib and mlxtend in Jupyter notebook. I am trying to get the Species name on the legend of the plot instead of 0, 1 and 2. So far my code is :
from sklearn import svm
from mlxtend.plotting import plot_decision_regions
X = iris[['SepalLengthCm', 'SepalWidthCm']]
y = iris['SpecieID']
clf = svm.SVC(decision_function_shape = 'ovo')
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)
I couldn't find how to replace 0,1 and 2 by the species names (Iris-setosa, Iris-versicolor and Iris-virginica).
I created the pandas DataFrame by :
import pandas as pd
iris = pd.read_csv("Iris.csv") # the iris dataset is now a Pandas DataFrame
iris = iris.assign(SepalRatio = iris['SepalLengthCm'] / iris['SepalWidthCm']).assign(PetalRatio = iris['PetalLengthCm'] / iris['PetalWidthCm']).assign(SepalMultiplied = iris['SepalLengthCm'] * iris['SepalWidthCm']).assign(PetalMultiplied = iris['PetalLengthCm'] * iris['PetalWidthCm'])
d = {"Iris-setosa" : 0, "Iris-versicolor": 1, "Iris-virginica": 2}
iris['SpecieID'] = iris['Species'].map(d).fillna(-1)



