Skip to content

style: apply ruff formatting and fix label mapping for #589#1157

Merged
rasbt merged 4 commits into
rasbt:masterfrom
mariam851:fix-labels-color-589
Jan 24, 2026
Merged

style: apply ruff formatting and fix label mapping for #589#1157
rasbt merged 4 commits into
rasbt:masterfrom
mariam851:fix-labels-color-589

Conversation

@mariam851
Copy link
Copy Markdown
Contributor

@mariam851 mariam851 commented Jan 16, 2026

Hi @rasbt,

I hope you are doing well.

I have submitted this PR to address issue #589, where plot_decision_regions was missing colors when dealing with non-consecutive or negative class labels (e.g., [-1, 1]).

The Problem: The function previously relied on the actual class label values as indices for color mapping, which caused issues when labels were not starting from 0 or contained negative integers.

The Solution: I modified the internal logic to map arbitrary class labels to a zero-indexed range (0, 1, 2...) specifically for the coloring and contouring process. This ensures that:

Decision regions are always colored correctly regardless of the label values.

The original labels are preserved for the scatter plot and legend to maintain data integrity.

Changes made:

Introduced a label_to_index mapping.

Mapped Z predictions to Z_indexed for the contourf and contour calls.

Verified the fix with a Perceptron classifier using [-1, 1] labels.

Applied Ruff for formatting and linting to ensure code quality.

Figure_1

Fixes #589

@mariam851 mariam851 force-pushed the fix-labels-color-589 branch from 6ed7a89 to f75a9b7 Compare January 16, 2026 01:50
@rasbt
Copy link
Copy Markdown
Owner

rasbt commented Jan 24, 2026

Thanks for the PR(s)! And sorry for the late reviews and responses. Mlxtend is an older, lower-priority project, and I am currently a bit swamped with other things, so I can't make as much time for it that I would like to. Thanks for trying to improve it via the PRs, though!

Copy link
Copy Markdown
Owner

@rasbt rasbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested it locally, and it works fine. Thanks!

@rasbt rasbt merged commit 366f717 into rasbt:master Jan 24, 2026
3 checks passed
@mariam851
Copy link
Copy Markdown
Contributor Author

Thank you for the review and merge. I appreciate your feedback and time, and I’m glad the fix was helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plot_decision_regions is missing the color when dealing with "-1" class labels

2 participants