8000 DOC use semilogx in lasso paths (#29264) · scikit-learn/scikit-learn@972e17f · GitHub
[go: up one dir, main page]

Skip to content

Commit 972e17f

Browse files
authored
DOC use semilogx in lasso paths (#29264)
1 parent dc1cad2 commit 972e17f

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

examples/linear_model/plot_lasso_coordinate_descent_path.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from itertools import cycle
1717

1818
import matplotlib.pyplot as plt
19-
import numpy as np
2019

2120
from sklearn import datasets
2221
from sklearn.linear_model import enet_path, lasso_path
@@ -49,41 +48,37 @@
4948

5049
plt.figure(1)
5150
colors = cycle(["b", "r", "g", "c", "k"])
52-
neg_log_alphas_lasso = -np.log10(alphas_lasso)
53-
neg_log_alphas_enet = -np.log10(alphas_enet)
5451
for coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors):
55-
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
56-
l2 = plt.plot(neg_log_alphas_enet, coef_e, linestyle="--", c=c)
52+
l1 = plt.semilogx(alphas_lasso, coef_l, c=c)
53+
l2 = plt.semilogx(alphas_enet, coef_e, linestyle="--", c=c)
5754

58-
plt.xlabel("-Log(alpha)")
55+
plt.xlabel("alpha")
5956
plt.ylabel("coefficients")
6057
plt.title("Lasso and Elastic-Net Paths")
61-
plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower left")
58+
plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower right")
6259
plt.axis("tight")
6360

6461

6562
plt.figure(2)
66-
neg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso)
6763
for coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors):
68-
l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c)
69-
l2 = plt.plot(neg_log_alphas_positive_lasso, coef_pl, linestyle="--", c=c)
64+
l1 = plt.semilogy(alphas_lasso, coef_l, c=c)
65+
l2 = plt.semilogy(alphas_positive_lasso, coef_pl, linestyle="--", c=c)
7066

71-
plt.xlabel("-Log(alpha)")
67+
plt.xlabel("alpha")
7268
plt.ylabel("coefficients")
7369
plt.title("Lasso and positive Lasso")
74-
plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower left")
70+
plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower right")
7571
plt.axis("tight")
7672

7773

7874
plt.figure(3)
79-
neg_log_alphas_positive_enet = -np.log10(alphas_positive_enet)
8075
for coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors):
81-
l1 = plt.plot(neg_log_alphas_enet, coef_e, c=c)
82-
l2 = plt.plot(neg_log_alphas_positive_enet, coef_pe, linestyle="--", c=c)
76+
l1 = plt.semilogx(alphas_enet, coef_e, c=c)
77+
l2 = plt.semilogx(alphas_positive_enet, coef_pe, linestyle="--", c=c)
8378

84-
plt.xlabel("-Log(alpha)")
79+
plt.xlabel("alpha")
8580
plt.ylabel("coefficients")
8681
plt.title("Elastic-Net and positive Elastic-Net")
87-
plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower left")
82+
plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower right")
8883
plt.axis("tight")
8984
plt.show()

0 commit comments

Comments
 (0)
0