Closed kcolombe closed 6 months ago
Hm, this looks kind of familiar. I think there was a particular matplotlib version that had that issue. E.g. as discussed in #149. Could you print your matplotlib version here so we can further dig into what's going on here?
import matplotlib matplotlib.version '3.8.0'
I did seem to solve it with
from matplotlib.colors import to_rgba, ListedColormap
`
def plot_decision_regions(X, y, classifier, resolution=0.02):
markers = ('o', 's', '^', 'v', '<') # Define marker styles for different classes
colors = ['red', 'blue', 'lightgreen', 'gray', 'cyan'] # Define colors for different classes
rgba_colors = [to_rgba(color) for color in colors] # Convert color names to RGBA format
cmap = ListedColormap(rgba_colors[:len(np.unique(y))]) # Create a colormap from the list of colors`
Oh I see, thanks for reporting! I think this is specifically a matplotlib 3.8 bug. If you downgrade to 3.7.2 or upgrade to 3.9, it should work fine. E.g. pip install matplotlib --upgrade
.
I added an extra check for Matplotlib 3.8 here, which is imported at the top of each notebook: https://github.com/rasbt/machine-learning-book/blob/be3ad1f5bc6ab614dfdaccaa085ba9d69074853c/python_environment_check.py#L40
Thank you very much
Hello. It should be simple but for some reason, I am having trouble getting the plot_decision_regions function to work. Any reason why red wouldn't be a valid color?