【问题标题】:How to obtain coefficients from Lasso Regression in R?如何从 R 中的套索回归中获得系数?
【发布时间】:2014-10-26 13:10:14
【问题描述】:

有人可以告诉我如何在 R 中的包 lars 中获取套索回归的系数吗?

例如如果代码是这样的:

     test_lasso=lars(A,B)

谢谢。

【问题讨论】:

    标签: r lasso-regression lars


    【解决方案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")
    

    【讨论】:

      猜你喜欢
      • 2014-11-28
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 2022-07-06
      • 1970-01-01
      • 2018-07-08
      相关资源
      最近更新 更多