style: apply ruff formatting and fix label mapping for #589 #1157
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.