Why do I get a non-zero intercept using the lasso even though I centered the response? It's my understanding that if I center $y$, the intercept should be 0. However, when using glmnet, I get a non-zero intercept doing this:
lasso_model = glmnet(x=bodyfat$x,y=bodyfat$y-mean(bodyfat$y),intercept=TRUE,alpha = 1,lambda = 1.5)

The intercept is given as $-45.53019$, but shouldn't it be 0 because I've taken the mean from the response?

It is not in general the case that centering $y$ produces an intercept of zero. Centering $y$ means that the average value of the centered variable is zero, but the intercept is the predicted value for $y$ when $x=0$.
To illustrate, try plotting bodyfat$y against bodyfat$x, and then plotting bodyfat$y - mean(bodyfat$y) against bodyfat$x, and think about what the axes mean. For example, does it even make sense for $x$ to be zero? If $x$ is height and $y$ is weight, then the intercept is the predicted weight (or difference from the mean in weight) at a height of zero.
