lasso_cv = LassoCV(fit_intercept=True, n_alphas=100, normalize=False) lasso_cv.fit(x_train, y_train) p_lasso_cv = lasso_cv.predict(x_test) print("#--------------------------------------") print("LassoCV Regression Result") print("r2_score = %.4f" % (r2_score(y_test, p_lasso_cv))) print("mean squared error = %.4f" % (mean_squared_error(y_test, p_lasso_cv))) print(sum(lasso_cv.coef_ == 0)) print("#--------------------------------------") print("\n") # Let's visualize the solution path lassop = lasso_cv.path(x_train, y_train) lassop_fig = plt.figure() lassop_plot = lassop_fig.add_subplot(1, 1, 1) lassop_plot.plot(np.log(lassop[0]), lassop[1].T) lassop_plot.set_xlabel("lambda value (log scale)") lassop_plot.set_ylabel("Coefficient estimate value") lassop_plot.set_title("lasso solution path") plt.savefig("lasso_path.jpg", dpi=300) plt.show() # ElasticNetCV: contained L1 and L2 regularization # CV == cross-validation en_cv = ElasticNetCV(fit_intercept=True, n_alphas=100, normalize=False,