Skip to content
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

MAINT Use class_of_interest in DecisionBoundaryDisplay #772

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ArturoAmorQ
Copy link
Collaborator

Since scikit-learn v1.4 DecisionBoundaryDisplay accepts class_of_interest for multiclass visualization. This feature is promised in the current version of the MOOC.

Notice that, as it requires updating the minimal version, it may change the experience of current enrolled participants.

@glemaitre glemaitre self-requested a review April 26, 2024 13:18
@@ -150,46 +150,38 @@

# %% tags=["solution"]
import numpy as np
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that we can simplify the code by using some groupby that will avoid using the loc here:

from matplotlib import cm

_, axs = plt.subplots(ncols=3, nrows=1, sharey=True, figsize=(12, 5))
plt.suptitle("Predicted probabilities for decision tree model", y=1.05)
plt.subplots_adjust(bottom=0.45)

for idx, (class_of_interest, data_class) in enumerate(
    data_test.groupby(by=target_test)
):
    axs[idx].set_title(f"Class {class_of_interest}")
    disp = DecisionBoundaryDisplay.from_estimator(
        tree,
        data_test,
        response_method="predict_proba",
        class_of_interest=class_of_interest,
        ax=axs[idx],
        vmin=0,
        vmax=1,
    )
    data_class.plot.scatter(
        x="Culmen Length (mm)",
        y="Culmen Depth (mm)",
        ax=axs[idx],
        marker="o",
        s=100,
        c="w",
        edgecolor="k",
    )

ax = plt.axes([0.15, 0.14, 0.7, 0.05])
plt.colorbar(
    cm.ScalarMappable(cmap="viridis"), cax=ax, orientation="horizontal"
)
_ = plt.title("Probability")

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel that we have less matplotlib boilerplate code in this case since we rely on pandas directly.

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.

None yet

2 participants