Skip to content

Commit

Permalink
DOC: more small edits to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lbluque committed Jul 25, 2023
1 parent 2a1f8ca commit f58dd6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
18 changes: 10 additions & 8 deletions examples/plot_adaptive.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
print(f" train rmse: {alasso_train['rmse']:.3f}")
print(f" test rmse: {alasso_test['rmse']:.3f}")

# plot model coefficients
fig, ax = plt.subplots()
ax.plot(coef, "o", label="True coefficients")
ax.plot(lasso_cv.best_estimator_.coef_, "o", label="Lasso", alpha=0.5)
ax.plot(alasso_cv.best_estimator_.coef_, "o", label="Adaptive Lasso", alpha=0.5)
ax.set_xlabel("covariate index")
ax.set_ylabel("coefficient value")
ax.legend()
fig.show()

# plot predicted values
fig, ax = plt.subplots()
ax.plot(y_test, lasso_cv.predict(X_test), "o", label="lasso", alpha=0.5)
Expand All @@ -89,11 +99,3 @@
ax.legend()
fig.show()

# plot model coefficients
fig, ax = plt.subplots()
ax.plot(coef, "o", label="True coefficients")
ax.plot(lasso_cv.best_estimator_.coef_, "o", label="Lasso", alpha=0.5)
ax.plot(alasso_cv.best_estimator_.coef_, "o", label="Adaptive Lasso", alpha=0.5)
ax.set_xlabel("covariate index")
ax.set_ylabel("coefficient value")
fig.show()
17 changes: 0 additions & 17 deletions examples/plot_line_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,3 @@
print(f" test r2: {l2l0_test['r2']:.3f}")
print(f" train rmse: {l2l0_train['rmse']:.3f}")
print(f" test rmse: {l2l0_test['rmse']:.3f}")

# plot predicted values
fig, ax = plt.subplots()
ax.plot(y_test, l2l0_cv.predict(X_test), "o", label="L2L0 line search", alpha=0.5)
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "k--")
ax.set_xlabel("true values")
ax.set_ylabel("predicted values")
ax.legend()
fig.show()

# plot model coefficients
fig, ax = plt.subplots()
ax.plot(coef, "o", label="True coefficients")
ax.plot(l2l0_cv.best_estimator_.coef_, "o", label="L2L0 line search", alpha=0.5)
ax.set_xlabel("covariate index")
ax.set_ylabel("coefficient value")
fig.show()
19 changes: 10 additions & 9 deletions examples/plot_stepwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,20 @@
print(f" train rmse: {stepwise_train['rmse']:.3f}")
print(f" test rmse: {stepwise_test['rmse']:.3f}")

# plot model coefficients
fig, ax = plt.subplots()
ax.plot(coef, "o", label="True coefficients")
ax.plot(stepwise.coef_[[0, 1, 2, 99]], "o", label="Stepwise (ridge)", alpha=0.5)
ax.plot(stepwise.coef_[range(3, 99)], "o", label="Stepwise (lasso)", alpha=0.5)
ax.set_xlabel("covariate index")
ax.set_ylabel("coefficient value")
ax.legend()
fig.show()

# plot predicted values
fig, ax = plt.subplots()
ax.plot(y_test, stepwise.predict(X_test), "o", label="Stepwise", alpha=0.5)
ax.plot([y_test.min(), y_test.max()], [y_test.min(), y_test.max()], "k--")
ax.set_xlabel("true values")
ax.set_ylabel("predicted values")
ax.legend()
fig.show()

# plot model coefficients
fig, ax = plt.subplots()
ax.plot(coef, "o", label="True coefficients")
ax.plot(stepwise.coef_, "o", label="Stepwise", alpha=0.5)
ax.set_xlabel("covariate index")
ax.set_ylabel("coefficient value")
fig.show()

0 comments on commit f58dd6a

Please sign in to comment.