How to obtain coefficients from Lasso Regression i

2019-07-22 04:34发布

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.

标签: r lasso lars
1条回答
Viruses.
2楼-- · 2019-07-22 04:50
   #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")
查看更多
登录 后发表回答