问题
Can someone tell me how to get the coefficients for lasso regression in package lars
in R?
For example if the code is like:
test_lasso=lars(A,B)
Thank you.
回答1:
#First get cross validation score:
test_lasso_cv=cv.lars(A,B)
# Find the best one
bestfraction = test_lasso_cv$index[which.min(test_lasso_cv$cv)]
#Find Coefficients
coef.lasso = predict(test_lasso,A),s=bestfraction,type="coefficient",mode="fraction")
来源:https://stackoverflow.com/questions/25620511/how-to-obtain-coefficients-from-lasso-regression-in-r