8000 DOC Rework voting classifier example by ArturoAmorQ · Pull Request #30985 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

DOC Rework voting classifier example #30985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 1, 2025

Conversation

ArturoAmorQ
Copy link
Member

Reference Issues/PRs

Related to #27151.

What does this implement/fix? Explain your changes.

This PR reworks the Plot the decision boundaries of a VotingClassifier example, introducing a notebook style (see #22406).

The narrative is extended to better cover the use of weights, therefore making the Plot class probabilities calculated by the VotingClassifier example obsolete.

Any other comments?

Extrapolating seemed to me a more interesting use-case for VotingClassifier other than just using different model families.

Copy link
github-actions bot commented Mar 12, 2025

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: ec42ff1. Link to the linter CI: here

@ArturoAmorQ ArturoAmorQ changed the title Rework voting classifier DOC Rework voting classifier example Mar 12, 2025
Copy link
Member
@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. It's a nice improvement.

ArturoAmorQ and others added 3 commits March 27, 2025 12:19
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
@lucyleeow lucyleeow closed this Apr 30, 2025
@lucyleeow lucyleeow reopened this Apr 30, 2025
@lucyleeow
Copy link
Member

Sorry for close, mis-click. Merged main so CI runs again and we can see the rendered docs.

Copy link
Member
@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Some nits, feel free to ignore.

No idea why the figure is not rendering properly in CI, maybe it's just me?


"""

# Authors: The scikit-learn developers
# SPDX-License-Identifier: BSD-3-Clause

from itertools import product
# %%
# We first generate a noisy XOR dataset, which is a binary classification task.
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth adding that it is not linearly separable?

print(f"Predicted class of VotingClassifier: {eclf.predict(test_sample).ravel()}")

# %%
# Soft votes can be thresholded as for any other probabilistic classifier.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be nice to add a sentence about thresholding here, e.g.

This allows you to set a threshold probability at which the positive class will be predicted, instead of simply selecting the class with the highest predicted probability.

# To convert soft predictions into hard predictions when weights are provided,
# the weighted average predicted probabilities are computed for each class.
# Then, the final class label is then derived from the class label with the
# highest average probability.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be nice to have the sentence:

"Which corresponds to the default threshold at 0.5 in the case of binary
classification."

here instead?

Comment on lines 1423 to 1424
.. figure:: ../auto_examples/ensemble/images/sphx_glr_plot_voting_decision_regions_001.png
:target: ../auto_examples/ensemble/plot_voting_decision_regions.html
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to have rendered properly:

image

The voting regressor figure below is rendered fine, and it seems to have the same syntax ? 🤷

Also I think we don't want the first figure now, as that just shows the XOR dataset? i.e. ..plot_voting_decision_regions_001.png -> ..plot_voting_decision_regions_002.png ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The render is working now. The problem was the special marker :: that was previously used to introduce a literal code block.

Copy link
Member

Choose a reason for hiding this comment

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

Ah of course!

Copy link
Member
@lucyleeow lucyleeow left a comment

Choose a reason for hiding this comment

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

Thank you, this is great and we get to remove a redundant example!

Co-authored-by: Lucy Liu <jliu176@gmail.com>
@lucyleeow lucyleeow merged commit 1527b1f into scikit-learn:main May 1, 2025
36 checks passed
@lucyleeow
Copy link
Member

Thank you!!

@ArturoAmorQ ArturoAmorQ deleted the rework_voting_classifier branch May 1, 2025 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
2A50
0