rasbt / mlxtend

A library of extension and helper modules for Python's data analysis and machine learning libraries.
https://rasbt.github.io/mlxtend/
Other
4.9k stars 867 forks source link

Custom class names for plot_decision_regions #737

Open rasbt opened 4 years ago

rasbt commented 4 years ago

We could add an explanation to the plot_decision_regions function to plot custom class names. E.g., like this

from mlxtend.plotting import plot_decision_regions
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.svm import SVC

# Loading some example data
iris = datasets.load_iris()
X = iris.data[:, [0, 2]]
y = iris.target

# Training a classifier
svm = SVC(C=0.5, kernel='linear')
svm.fit(X, y)

# Plotting decision regions
ax = plot_decision_regions(X, y, clf=svm)

handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, ['Setosa', 'Versicolor', 'Virginica'],
          framealpha=0.3, scatterpoints=1, loc='upper left')

plt.show()