如何从R中的套索回归获得系数? [英] How to obtain coefficients from Lasso Regression in R?
本文介绍了如何从R中的套索回归获得系数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如何在R中的包lars
中获得套索回归的系数吗?
Can someone tell me how to get the coefficients for lasso regression in package lars
in R?
例如,如果代码如下:
test_lasso=lars(A,B)
谢谢.
推荐答案
#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")
这篇关于如何从R中的套索回归获得系数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文