GokuMohandas / Made-With-ML

Learn how to design, develop, deploy and iterate on production-grade ML applications.
https://madewithml.com
MIT License
37.32k stars 5.92k forks source link

Missing legend in the plot of Logistic Regression #229

Closed nguyenvulong closed 1 year ago

nguyenvulong commented 1 year ago

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()
ShathishWarmaS commented 1 year ago

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()

nguyenvulong commented 1 year ago

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

chris-caballero commented 1 year ago

Can I work on this?

yuboona commented 1 year ago

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