DOC fix labels in legend of plot_logistic example
@@ -13,11 +13,10 @@ i.e. class one or two, using the logistic curve.
# Code source: Gael Varoquaux
# License: BSD 3 clause
-import numpy as np
import matplotlib.pyplot as plt
-
-from sklearn.linear_model import LogisticRegression, LinearRegression
+import numpy as np
from scipy.special import expit
+from sklearn.linear_model import LinearRegression, LogisticRegression
# Generate a toy dataset, it's just a straight line with some Gaussian noise:
xmin, xmax = -5, 5
@@ -37,15 +36,20 @@ clf.fit(X, y)
# and plot the result
plt.figure(1, figsize=(4, 3))
plt.clf()
-plt.scatter(X.ravel(), y, color="black", zorder=20)
+plt.scatter(X.ravel(), y, label="example data", color="black", zorder=20)
X_test = np.linspace(-5, 10, 300)
loss = expit(X_test * clf.coef_ + clf.intercept_).ravel()
-plt.plot(X_test, loss, color="red", linewidth=3)
+plt.plot(X_test, loss, label="Logistic Regression Model", color="red", linewidth=3)
ols = LinearRegression()
ols.fit(X, y)
-plt.plot(X_test, ols.coef_ * X_test + ols.intercept_, linewidth=1)
+plt.plot(
+ X_test,
+ ols.coef_ * X_test + ols.intercept_,
+ label="Linear Regression Model",
+ linewidth=1,
+)
plt.axhline(0.5, color=".5")
plt.ylabel("y")
@@ -55,7 +59,6 @@ plt.yticks([0, 0.5, 1])
plt.ylim(-0.25, 1.25)
plt.xlim(-4, 10)
plt.legend(
- ("Logistic Regression Model", "Linear Regression Model"),
loc="lower right",
fontsize="small",
)
