From 9bcd680e6133ebfaa40577b48503bc99e10ab62a Mon Sep 17 00:00:00 2001 From: mathurinm Date: Fri, 14 Jun 2024 16:28:57 +0200 Subject: [PATCH 1/2] DOC enh use semilogx in lasso paths --- .../plot_lasso_coordinate_descent_path.py | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/linear_model/plot_lasso_coordinate_descent_path.py b/examples/linear_model/plot_lasso_coordinate_descent_path.py index 4d89095a010cd..44a960205ffeb 100644 --- a/examples/linear_model/plot_lasso_coordinate_descent_path.py +++ b/examples/linear_model/plot_lasso_coordinate_descent_path.py @@ -49,41 +49,37 @@ plt.figure(1) colors = cycle(["b", "r", "g", "c", "k"]) -neg_log_alphas_lasso = -np.log10(alphas_lasso) -neg_log_alphas_enet = -np.log10(alphas_enet) for coef_l, coef_e, c in zip(coefs_lasso, coefs_enet, colors): - l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c) - l2 = plt.plot(neg_log_alphas_enet, coef_e, linestyle="--", c=c) + l1 = plt.semilogx(alphas_lasso, coef_l, c=c) + l2 = plt.semilogx(alphas_enet, coef_e, linestyle="--", c=c) -plt.xlabel("-Log(alpha)") +plt.xlabel("alpha") plt.ylabel("coefficients") plt.title("Lasso and Elastic-Net Paths") -plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower left") +plt.legend((l1[-1], l2[-1]), ("Lasso", "Elastic-Net"), loc="lower right") plt.axis("tight") plt.figure(2) -neg_log_alphas_positive_lasso = -np.log10(alphas_positive_lasso) for coef_l, coef_pl, c in zip(coefs_lasso, coefs_positive_lasso, colors): - l1 = plt.plot(neg_log_alphas_lasso, coef_l, c=c) - l2 = plt.plot(neg_log_alphas_positive_lasso, coef_pl, linestyle="--", c=c) + l1 = plt.semilogy(alphas_lasso, coef_l, c=c) + l2 = plt.semilogy(alphas_positive_lasso, coef_pl, linestyle="--", c=c) -plt.xlabel("-Log(alpha)") +plt.xlabel("alpha") plt.ylabel("coefficients") plt.title("Lasso and positive Lasso") -plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower left") +plt.legend((l1[-1], l2[-1]), ("Lasso", "positive Lasso"), loc="lower right") plt.axis("tight") plt.figure(3) -neg_log_alphas_positive_enet = -np.log10(alphas_positive_enet) for coef_e, coef_pe, c in zip(coefs_enet, coefs_positive_enet, colors): - l1 = plt.plot(neg_log_alphas_enet, coef_e, c=c) - l2 = plt.plot(neg_log_alphas_positive_enet, coef_pe, linestyle="--", c=c) + l1 = plt.semilogx(alphas_enet, coef_e, c=c) + l2 = plt.semilogx(alphas_positive_enet, coef_pe, linestyle="--", c=c) -plt.xlabel("-Log(alpha)") +plt.xlabel("alpha") plt.ylabel("coefficients") plt.title("Elastic-Net and positive Elastic-Net") -plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower left") +plt.legend((l1[-1], l2[-1]), ("Elastic-Net", "positive Elastic-Net"), loc="lower right") plt.axis("tight") plt.show() From 4f89b7ce35a1b33e42f1efe9a06f293cff78e74e Mon Sep 17 00:00:00 2001 From: mathurinm Date: Fri, 14 Jun 2024 16:38:33 +0200 Subject: [PATCH 2/2] lint --- examples/linear_model/plot_lasso_coordinate_descent_path.py | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/linear_model/plot_lasso_coordinate_descent_path.py b/examples/linear_model/plot_lasso_coordinate_descent_path.py index 44a960205ffeb..dd88e57a6f196 100644 --- a/examples/linear_model/plot_lasso_coordinate_descent_path.py +++ b/examples/linear_model/plot_lasso_coordinate_descent_path.py @@ -16,7 +16,6 @@ from itertools import cycle import matplotlib.pyplot as plt -import numpy as np from sklearn import datasets from sklearn.linear_model import enet_path, lasso_path