Last active
March 4, 2022 19:08
-
-
Save xiaowei1234/b2ebaac57769e2e50df98d62234904ae to your computer and use it in GitHub Desktop.
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, Ridge | |
import statsmodels.api as sm | |
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 Poisson Reg', Preg_alpha_1.coef_) | |
Preg_alpha_2 = PoissonRegressor(alpha=2., fit_intercept=False).fit(X_array*4., y) | |
print('alpha 2 Poisson Reg', 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_) | |
Rreg_alpha_1 = Ridge(alpha=1., fit_intercept=False).fit(X_array, y) | |
print('alpha 1 Ridge OLS', Rreg_alpha_1.coef_) | |
Rreg_alpha_2 = Ridge(alpha=2., fit_intercept=False).fit(X_array*4, y) | |
print('alpha 1 Ridge OLS', Rreg_alpha_1.coef_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment