How to obtain coefficients from Lasso Regression in R?

谁说我不能喝 提交于 2020-01-04 14:30:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!