Predict response after Lasso
조회 수: 3 (최근 30일)
이전 댓글 표시
I am using Lasso to remove redundant predictors by using cross-validated fits, essentially following this guide. To make predictions on the Train set, I multiplied the Train and B(:,FitInfo.IndexMinMSE) matrices. The predicted values somehow are not close to the actual response of the Train set. Am I missing something here? How do I predict response using coefficients obtained from Lasso?
X = x2fx(X)
rng default % For reproducibility
[B,FitInfo] = lasso(X,Y,'CV',10);
lassoPlot(B,FitInfo,'PlotType','CV'); % Look at MSE vs Lambda
coeff = B(:,FitInfo.IndexMinMSE); % Regression coefficients for min MSE, use these coefficients.
Ypredict = X * coeff; % Predicted response
댓글 수: 0
답변 (1개)
Lonoko
2018년 1월 12일
The first column of X corresponds to the constant (see help for x2fx), but Matlab doesn't save the constant value in B (coef(1)=0), so your predictions are biased. The predicted response is: Ypredict = X * coeff + FitInfo.Intercept(IndexMinMSE);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!