how can I add a bias in lassoglm?
6 views (last 30 days)
Show older comments
I am fitting data with a lot predictors (between 150 and 200) and a high dergree of colinearity between the predictors. Initially I used [par,~,stat] = glmfit(dX, y,'poisson','constant','on') which works well up to about 100 predictors but then the beta start to be unreasonably small and big. So now I try to use lassoglm trying to keep the beta small by giving it a single lambda (of 0.001 or so). But where can I set the bias (or constant) and where will I see the beta for the it after the fit?
0 Comments
Answers (1)
Aditya
on 14 Jul 2025
Hi Debora,
When you use lassoglm in MATLAB , the intercept (bias/constant) is handled automatically; you do not set it manually.The coefficients for predictors are returned in the output B.The intercept is returned separately in FitInfo.Intercept.By default, lassoglm always fits an intercept unless you specify 'Intercept',false.
Example:
% Fit a Poisson GLM with Lasso regularization and a fixed lambda
[B, FitInfo] = lassoglm(dX, y, 'poisson', 'Lambda', 0.001);
% B contains the coefficients for your predictors (excluding the intercept)
% FitInfo.Intercept contains the intercept (bias/constant) term
% To get the full set of coefficients including the intercept:
fullBeta = [FitInfo.Intercept; B];
% To make predictions on new data (dXnew):
yhat = glmval([FitInfo.Intercept; B], dXnew, FitInfo.Link);
Following are the documentation links that you can refer to :
0 Comments
See Also
Categories
Find more on Generalized Linear Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!