Created
March 4, 2022 17:02
-
-
Save xiaowei1234/08dbd72695e6d263546c973a9a5a330b to your computer and use it in GitHub Desktop.
A comparison of GLM vs OLS lasso penalty regression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.linear_model import PoissonRegressor, Lasso | |
X_array = np.asarray([[1, 2], [1, 3], [1, 4], [1, 3]]) | |
y = np.asarray([2, 2, 3, 2]) | |
Preg_alpha_1 = PoissonRegressor(alpha=1., fit_intercept=False).fit(X_array, y) | |
print('alpha 1', Preg_alpha_1.coef_) | |
Preg_alpha_2 = PoissonRegressor(alpha=2., fit_intercept=False).fit(X_array/2., y) | |
print('alpha 2', Preg_alpha_2.coef_) | |
Lreg_alpha_1 = Lasso(alpha=1., fit_intercept=False).fit(X_array, y) | |
print('alpha 1 Lasso OLS', Lreg_alpha_1.coef_) | |
Lreg_alpha_2 = Lasso(alpha=2., fit_intercept=False).fit(X_array/2., y) | |
print('alpha 2 Lasso OLS', Lreg_alpha_2.coef_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment