2

I am trying to reproduce the example in this post, which produces this figure.

enter image description here

The colored regions above are plotted by mlxtend.plotting (version '0.14.0').

With the default settings on colab, this code

from mlxtend.plotting import plot_decision_regions
plot_decision_regions(X, y, clf=ppn)

produces this figure.

enter image description here

The data points have been plotted while the bottom region has not.

Is it possible to set the color for the bottom region with mlxtend.plotting?

  • [Issue](https://github.com/rasbt/mlxtend/issues/589) has been filed. –  Sep 17 '19 at 12:50

2 Answers2

1

it seems like a bug derived by the classification of two regions, if you try and separate 3 clusters as the following example it will work.

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import itertools
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from mlxtend.classifier import EnsembleVoteClassifier
from mlxtend.data import iris_data
from mlxtend.plotting import plot_decision_regions

# Initializing Classifiers
clf1 = LogisticRegression(random_state=0)
clf2 = RandomForestClassifier(random_state=0)
clf3 = SVC(random_state=0, probability=True)
eclf = EnsembleVoteClassifier(clfs=[clf1, clf2, clf3],
                              weights=[2, 1, 1], voting='soft')

# Loading some example data
X, y = iris_data()
X = X[:,[0, 2]]

# Plotting Decision Regions

gs = gridspec.GridSpec(2, 2)
fig = plt.figure(figsize=(10, 8))

labels = ['Logistic Regression',
          'Random Forest',
          'RBF kernel SVM',
          'Ensemble']

for clf, lab, grd in zip([clf1, clf2, clf3, eclf],
                         labels,
                         itertools.product([0, 1],
                         repeat=2)):
    clf.fit(X, y)
    ax = plt.subplot(gs[grd[0], grd[1]])
    fig = plot_decision_regions(X=X, y=y,
                                clf=clf, legend=2)
    plt.title(lab)

plt.show()

Try and ask directly on their github directory: https://github.com/rasbt/mlxtend

Matteo Peluso
  • 452
  • 1
  • 6
  • 23
0

I think it's possible. You can use the colors parameter instead, I think it is much easier. You should try this one, is this what you are looking for?

fig = plot_decision_regions(
  X=X,
  y=y.astype(int),
  clf=clf,
  legend=2,
  colors='yellow,red'
)

Result Example

Valentin Vignal
  • 6,151
  • 2
  • 33
  • 73
BryanO
  • 1