8000 Adaptive lasso by henridwyer · Pull Request #4912 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Adaptive lasso #4912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""
========================================
Lasso and Elastic Net for Sparse Signals
========================================
========================================================
Lasso, Adaptive Lasso and Elastic Net for Sparse Signals
========================================================

Estimates Lasso and Elastic-Net regression models on a manually generated
sparse signal corrupted with an additive noise. Estimated coefficients are
compared with the ground-truth.
Estimates Lasso, Adaptive Lasso and Elastic-Net regression models on a
manually generated sparse signal corrupted with an additive noise.
Estimated coefficients are compared with the ground-truth.

"""
print(__doc__)
Expand Down Expand Up @@ -47,6 +47,17 @@
print(lasso)
print("r^2 on test data : %f" % r2_score_lasso)

###############################################################################
# Adaptive Lasso
from sklearn.linear_model import AdaptiveLasso

ada_lasso = AdaptiveLasso(alpha=alpha)

y_pred_ada_lasso = ada_lasso.fit(X_train, y_train).predict(X_test)
r2_score_ada_lasso = r2_score(y_test, y_pred_ada_lasso)
print(ada_lasso)
print("r^2 on test data : %f" % r2_score_ada_lasso)

###############################################################################
# ElasticNet
from sklearn.linear_model import ElasticNet
Expand All @@ -62,8 +73,10 @@
label='Elastic net coefficients')
plt.plot(lasso.coef_, color='gold', linewidth=2,
label='Lasso coefficients')
plt.plot(ada_lasso.coef_, color='red', linewidth=2,
label='Adaptive Lasso coefficients')
plt.plot(coef, '--', color='navy', label='original coefficients')
plt.legend(loc='best')
plt.title("Lasso R^2: %f, Elastic Net R^2: %f"
% (r2_score_lasso, r2_score_enet))
plt.title("Lasso R^2: %f, Adaptive Lasso R^2: %f, Elastic Net R^2: %f"
% (r2_score_lasso, r2_score_ada_lasso, r2_score_enet))
plt.show()
9 changes: 5 additions & 4 deletions sklearn/linear_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
from .bayes import BayesianRidge, ARDRegression
from .least_angle import (Lars, LassoLars, lars_path, LarsCV, LassoLarsCV,
LassoLarsIC)
from .coordinate_descent import (Lasso, ElasticNet, LassoCV, ElasticNetCV,
lasso_path, enet_path, MultiTaskLasso,
MultiTaskElasticNet, MultiTaskElasticNetCV,
MultiTaskLassoCV)
from .coordinate_descent import (Lasso, ElasticNet, AdaptiveLasso,
LassoCV, ElasticNetCV, lasso_path, enet_path,
MultiTaskLasso, MultiTaskElasticNet,
MultiTaskElasticNetCV, MultiTaskLassoCV)
from .huber import HuberRegressor
from .sgd_fast import Hinge, Log, ModifiedHuber, SquaredLoss, Huber
from .stochastic_gradient import SGDClassifier, SGDRegressor
Expand All @@ -36,6 +36,7 @@
from .theil_sen import TheilSenRegressor

__all__ = ['ARDRegression',
'AdaptiveLasso',
'BayesianRidge',
'ElasticNet',
'ElasticNetCV',
Expand Down
Loading
0