|
16 | 16 | from itertools import cycle
|
17 | 17 |
|
18 | 18 | import matplotlib.pyplot as plt
|
19 |
| -import numpy as np |
20 | 19 |
|
21 | 20 | from sklearn import datasets
|
22 | 21 | from sklearn.linear_model import enet_path, lasso_path
|
|
49 | 48 |
|
50 | 49 | plt.figure(1)
|
51 | 50 | 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) |
54 | 51 | 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) |
57 | 54 |
|
58 |
| -plt.xlabel("-Log(alpha)") |
| 55 | +plt.xlabel("alpha") |
59 | 56 | plt.ylabel("coefficients")
|
60 | 57 | 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") |
62 | 59 | plt.axis("tight")
|
63 | 60 |
|
64 | 61 |
|
65 | 62 | plt.figure(2)
|
66 |
| -neg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso) |
67 | 63 | 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) |
70 | 66 |
|
71 |
| -plt.xlabel("-Log(alpha)") |
| 67 | +plt.xlabel("alpha") |
72 | 68 | plt.ylabel("coefficients")
|
73 | 69 | 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") |
75 | 71 | plt.axis("tight")
|
76 | 72 |
|
77 | 73 |
|
78 | 74 | plt.figure(3)
|
79 |
| -neg_log_alphas_positive_enet = -np.log10(alphas_positive_enet) |
80 | 75 | 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) |
83 | 78 |
|
84 |
| -plt.xlabel("-Log(alpha)") |
| 79 | +plt.xlabel("alpha") |
85 | 80 | plt.ylabel("coefficients")
|
86 | 81 | 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") |
88 | 83 | plt.axis("tight")
|
89 | 84 | plt.show()
|
0 commit comments