style: apply ruff formatting and fix label mapping for #589#1157
Merged
Conversation
6ed7a89 to
f75a9b7
Compare
Owner
|
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! |
rasbt
approved these changes
Jan 24, 2026
Owner
rasbt
left a comment
There was a problem hiding this comment.
Tested it locally, and it works fine. Thanks!
Contributor
Author
|
Thank you for the review and merge. I appreciate your feedback and time, and I’m glad the fix was helpful. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Fixes #589