Skip to content

DOC Add link to plot_classification_probability.py - #26978

Closed
paularilo wants to merge 2 commits into
scikit-learn:mainfrom
paularilo:pyladyprl
Closed

paularilo wants to merge 2 commits into
scikit-learn:mainfrom
paularilo:pyladyprl

Conversation

@paularilo

Copy link
Copy Markdown

Reference Issues/PRs

Towards #26927

What does this implement/fix? Explain your changes.

Commented the function in detail

Any other comments?

cc @adrinjalali @glemaitre

@adrinjalali adrinjalali changed the title Pyladyprl DOC Add link to plot_classification_probability.py Aug 2, 2023

@adrinjalali adrinjalali left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@glemaitre this one I think it'd make sense to link from different classifiers. At the same time, it's a toy dataset, I'm not sure how relevant it is in real usecases.

@@ -30,16 +32,39 @@
from sklearn.metrics import accuracy_score
from sklearn.svm import SVC

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In modern examples, we move imports to the cell where they're first used instead of leaving them on the top of the example.

Comment on lines +47 to +48
# CLASSIFIER INITIALIZATION
# -------------------------------------------------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# CLASSIFIER INITIALIZATION
# -------------------------------------------------------------
# Classifier Initialization
# -------------------------

Comment on lines +54 to +58
#This classifier is not inherently designed for multiclass classification. As a consequence,
#it faces more challenges in distinguishing between class 2 and class 3 compared to the other estimators.
#-Linear Support Vector Classifier (SVC) with C as the regularization parameter
#and probability set to True for obtaining classification probabilities.
#-Gaussian Process Classifier (GPC) using the specified Gaussian Radial Basis Function (RBF) kernel.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

some lines here are too long.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You also need to have a space after the # character and make sure that a return the line is actually well aligned such as:

# - first item
# - second item split on several
#   lines
# - third item

plt.colorbar(imshow_handle, cax=ax, orientation="horizontal")

# Show the plot
plt.show()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

would be nice to have a conclusion as well if it makes sense.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably here we should mention if a classifier has difficulty distinguishing between 2 classes.

Comment on lines +36 to +37
# Load Iris dataset
# -------------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Load Iris dataset
# -------------------------
# Load Iris dataset
# -----------------

# Load Iris dataset
# -------------------------
# First, we load the Iris data as a pandas dataframe.
iris = datasets.load_iris()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
iris = datasets.load_iris()
iris = datasets.load_iris(as_frame=True)

iris = datasets.load_iris()
X = iris.data[:, 0:2] # we only take the first two features for visualization
# We only take the first two features for visualization.
X = iris.data[:, 0:2]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
X = iris.data[:, 0:2]
X = iris.data[["sepal length (cm)", "sepal width (cm)"]]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's use a dataframe, it is more explicit on what is happening I find.

Comment on lines +54 to +58
#This classifier is not inherently designed for multiclass classification. As a consequence,
#it faces more challenges in distinguishing between class 2 and class 3 compared to the other estimators.
#-Linear Support Vector Classifier (SVC) with C as the regularization parameter
#and probability set to True for obtaining classification probabilities.
#-Gaussian Process Classifier (GPC) using the specified Gaussian Radial Basis Function (RBF) kernel.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You also need to have a space after the # character and make sure that a return the line is actually well aligned such as:

# - first item
# - second item split on several
#   lines
# - third item

Comment on lines +84 to +85
# Plot classification probabilities for each classifier
# -----------------------------------------------------------

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Plot classification probabilities for each classifier
# -----------------------------------------------------------
# Plot classification probabilities for each classifier
# -----------------------------------------------------

plt.subplot(n_classifiers, n_classes, index * n_classes + k + 1)
plt.title("Class %d" % k)

# Add ylabel to the leftmost subplots

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need

plt.xticks(())
plt.yticks(())

# Mark the actual data points on the plot if they belong to the current class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# Mark the actual data points on the plot if they belong to the current class
# For each class, plot the data point corresponding to the class

if idx.any():
plt.scatter(X[idx, 0], X[idx, 1], marker="o", c="w", edgecolor="k")

# Create a color bar for the probability values

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need

plt.title("Probability")
plt.colorbar(imshow_handle, cax=ax, orientation="horizontal")

# Show the plot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need

plt.colorbar(imshow_handle, cax=ax, orientation="horizontal")

# Show the plot
plt.show()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is probably here we should mention if a classifier has difficulty distinguishing between 2 classes.

@glemaitre

Copy link
Copy Markdown
Member

@paularilo Do you wish to address the reviews raised by @adrinjalali and myself such that we can merge this PR?

@adrinjalali adrinjalali added Stalled help wanted good first issue Easy with clear instructions to resolve labels Dec 5, 2023
@lebaudantoine

lebaudantoine commented Dec 6, 2023 •

Copy link
Copy Markdown

Hi @adrinjalali and @glemaitre, I would be more than happy to provide help on this PR. May I work on it and adress your comments?

@glemaitre

Copy link
Copy Markdown
Member

@lebaudantoine Since this PR is currently stalled, feel free to take over. You can include the changes proposed in the changes proposed during the review process and open a new PR that supersedes this PR.

@lebaudantoine

Copy link
Copy Markdown

thx @glemaitre will do !

@adrinjalali

Copy link
Copy Markdown
Member

Closing as stalled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation good first issue Easy with clear instructions to resolve help wanted Stalled

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants