Skip to content

Conversation

@mariam851
Copy link
Contributor

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

@mariam851 mariam851 force-pushed the fix-labels-color-589 branch from 6ed7a89 to f75a9b7 Compare January 16, 2026 01:50
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.

1 participant