How to get interception from a linear model with lasso (lars R package)

It’s hard for me to find the model evaluated by the R package larsfor my data.

For example, I create a fake dataset x and the corresponding y values ​​as follows:

x = cbind(runif(100),rnorm(100))
colnames(x) = c("a","b")
y = 0.5 + 3 * x[,1,drop = FALSE]

Next, I train a model that uses lasso regularization using the lars function:

m = lars(x,y,type = "lasso", normalize = FALSE, intercept = TRUE)

Now I would like to know what the evaluation model ( that I know to be: y = 0.5 + 3 * x[,1] + 0 * x[,2]) is

I'm only interested in the coefficients obtained in the last step:

cf = predict(m, x, s=1, mode = "fraction", type = "coef")$coef
cf
a b 
3 0

These are the odds I expect, but I cannot find a way to get the interception ( 0.5) from m.

I tried to check the code predict.larswhere the substitution is performed as such:

fit = drop(scale(newx, 
           object$meanx, FALSE) %*% t(newbetas)) + object$mu)

, y (object $mu), , . ?

+4
1

intercept=T lars x y. .

predict(m,data.frame(a=0,b=0),s=2)$fit, y, 0 ( )

+4

Source: https://habr.com/ru/post/1524565/


All Articles