Missing legend in the plot of Logistic Regression #48

Closed
opened 2025-11-02 00:02:23 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @nguyenvulong on GitHub (May 7, 2023).

Problem: only malignant legend was shown ( plot data section of the Logistic Regression lesson.)
image

Fix
I am not sure if I should create a PR for a notebook ... so I created this issue with a working code instead. Please see below

# Define X and y
X = df[["leukocyte_count", "blood_pressure"]].values
y = df["tumor_class"].values

# Split the data into separate arrays for benign and malignant classes
X_benign = X[y == "benign"]
X_malignant = X[y == "malignant"]

# Plot the data for each class separately
fig, ax = plt.subplots()
ax.scatter(X_benign[:, 0], X_benign[:, 1], c="blue", s=25, edgecolors="k", label="benign")
ax.scatter(X_malignant[:, 0], X_malignant[:, 1], c="red", s=25, edgecolors="k", label="malignant")
ax.set_xlabel("leukocyte count")
ax.set_ylabel("blood pressure")
ax.legend(loc="upper right")
plt.show()
Originally created by @nguyenvulong on GitHub (May 7, 2023). **Problem:** only `malignant` legend was shown ( `plot data` section of the [Logistic Regression](https://madewithml.com/courses/foundations/logistic-regression/) lesson.) ![image](https://user-images.githubusercontent.com/1311412/236676696-e0bc6e75-892c-427a-a5ed-12c619d609e0.png) **Fix** I am not sure if I should create a PR for a notebook ... so I created this issue with a working code instead. Please see below ``` # Define X and y X = df[["leukocyte_count", "blood_pressure"]].values y = df["tumor_class"].values # Split the data into separate arrays for benign and malignant classes X_benign = X[y == "benign"] X_malignant = X[y == "malignant"] # Plot the data for each class separately fig, ax = plt.subplots() ax.scatter(X_benign[:, 0], X_benign[:, 1], c="blue", s=25, edgecolors="k", label="benign") ax.scatter(X_malignant[:, 0], X_malignant[:, 1], c="red", s=25, edgecolors="k", label="malignant") ax.set_xlabel("leukocyte count") ax.set_ylabel("blood pressure") ax.legend(loc="upper right") plt.show() ```
Author
Owner

@ShathishWarmaS commented on GitHub (May 26, 2023):

Both are showing
Screenshot 1945-03-05 at 1 45 54 PM

Plot the data for each class separately

fig, ax = plt.subplots()
ax.scatter(X_benign[:, 0], X_benign[:, 1], c="blue", s=25, edgecolors="k", label="benign")
ax.scatter(X_malignant[:, 0], X_malignant[:, 1], c="red", s=25, edgecolors="k", label="malignant")
ax.set_xlabel("leukocyte count")
ax.set_ylabel("blood pressure")
ax.legend(loc="upper right")
plt.show()

@ShathishWarmaS commented on GitHub (May 26, 2023): Both are showing <img width="1440" alt="Screenshot 1945-03-05 at 1 45 54 PM" src="https://github.com/GokuMohandas/Made-With-ML/assets/103341418/0b7e0c51-87ee-4724-8de6-18a1e1365271"> # Plot the data for each class separately fig, ax = plt.subplots() ax.scatter(X_benign[:, 0], X_benign[:, 1], c="blue", s=25, edgecolors="k", label="benign") ax.scatter(X_malignant[:, 0], X_malignant[:, 1], c="red", s=25, edgecolors="k", label="malignant") ax.set_xlabel("leukocyte count") ax.set_ylabel("blood pressure") ax.legend(loc="upper right") plt.show()
Author
Owner

@nguyenvulong commented on GitHub (May 29, 2023):

@ShathishWarmaS I know. What I was talking about is that the original code, which is plotting both classes using one scatter, is not working.

@nguyenvulong commented on GitHub (May 29, 2023): @ShathishWarmaS I know. What I was talking about is that the [**original code**](https://madewithml.com/courses/foundations/logistic-regression/), which is plotting both classes using one `scatter`, is **not** working.
Author
Owner

@chris-caballero commented on GitHub (Jul 20, 2023):

Can I work on this?

@chris-caballero commented on GitHub (Jul 20, 2023): Can I work on this?
Author
Owner

@yuboona commented on GitHub (Jul 20, 2023):

您的邮件我已收到,将尽快回复!!

@yuboona commented on GitHub (Jul 20, 2023): 您的邮件我已收到,将尽快回复!!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/Made-With-ML#48