use semilogx for a more readable xaxis
@@ -80,14 +80,12 @@ alpha_aic_ = model_aic.alpha_
def plot_ic_criterion(model, name, color):
- alpha_ = model.alpha_ + EPSILON
- alphas_ = model.alphas_ + EPSILON
criterion_ = model.criterion_
- plt.plot(-np.log10(alphas_), criterion_, '--', color=color,
+ plt.semilogx(model.alphas_ + EPSILON, criterion_, '--', color=color,
linewidth=3, label='%s criterion' % name)
- plt.axvline(-np.log10(alpha_), color=color, linewidth=3,
+ plt.axvline(model.alpha_ + EPSILON, color=color, linewidth=3,
label='alpha: %s estimate' % name)
- plt.xlabel('-log(alpha)')
+ plt.xlabel(r'$\alpha$')
plt.ylabel('criterion')
@@ -108,19 +106,17 @@ model = LassoCV(cv=20).fit(X, y)
t_lasso_cv = time.time() - t1
# Display results
-m_log_alphas = -np.log10(model.alphas_ + EPSILON)
-
plt.figure()
ymin, ymax = 2300, 3800
-plt.plot(m_log_alphas, model.mse_path_, ':')
-plt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',
+plt.semilogx(model.alphas_ + EPSILON, model.mse_path_, ':')
+plt.plot(model.alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',
label='Average across the folds', linewidth=2)
-plt.axvline(-np.log10(model.alpha_ + EPSILON), linestyle='--', color='k',
+plt.axvline(model.alpha_ + EPSILON, linestyle='--', color='k',
label='alpha: CV estimate')
plt.legend()
-plt.xlabel('-log(alpha)')
+plt.xlabel(r'$\alpha$')
plt.ylabel('Mean square error')
plt.title('Mean square error on each fold: coordinate descent '
'(train time: %.2fs)' % t_lasso_cv)
@@ -137,17 +133,15 @@ model = LassoLarsCV(cv=20).fit(X, y)
t_lasso_lars_cv = time.time() - t1
# Display results
-m_log_alphas = -np.log10(model.cv_alphas_ + EPSILON)
-
plt.figure()
-plt.plot(m_log_alphas, model.mse_path_, ':')
-plt.plot(m_log_alphas, model.mse_path_.mean(axis=-1), 'k',
+plt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_, ':')
+plt.semilogx(model.cv_alphas_ + EPSILON, model.mse_path_.mean(axis=-1), 'k',
label='Average across the folds', linewidth=2)
-plt.axvline(-np.log10(model.alpha_), linestyle='--', color='k',
+plt.axvline(model.alpha_, linestyle='--', color='k',
label='alpha CV')
plt.legend()
-plt.xlabel('-log(alpha)')
+plt.xlabel(r'$\alpha$')
plt.ylabel('Mean square error')
plt.title('Mean square error on each fold: Lars (train time: %.2fs)'
% t_lasso_lars_cv)
