How to get the predicted variables name in LASSO function?
Show older comments
Hi there,
I am currently using the function [ba,fitinfoa] = lasso() as a feature selection. And, in the Matlab documentation for this function (https://www.mathworks.com/help/stats/lasso.html) says that the output [fitinfoa] gives these variables in the structure: Intercept, Lambda, Alpha, DF, MSE, PredictorNames, UseCovariance, SE, LambdaMinMSE, Lambda1SE, IndexMinMSE, and Index1SE.
So, here is my question: How exactly should be in the function for the fitinfoa displays the actual features chosen by the model in the PredictorNames.
Here is my code:
%% LASSO
var_names_test = {'a1','a2','a3','a4','a5','a6','a7','a8','a9','a10'};
test_array = rand(10:10);
predictor_array = [1 0 1 0 0 0 1 0 1 1].';
[ba,fitinfoa] = lasso(test_array,double(predictor_array),'CV',5,'Alpha',1);
Lasso_all = lassoPlot(ba,fitinfoa,'PlotType','L1','XScale','linear',...
'PredictorNames',var_names_test);
set(findall(gcf,'-property','FontSize'),'FontSize',9)
set(findall(gcf,'-property','LineWidth'),'LineWidth',1)
box off
xlabel('L1 norm')
ylabel('Regression coefficients')
legend('show')
%% Structured output (call fitinfoa)
fitinfoa
%should display something like this
%struct with fields:
%Intercept: [2.393890179365678 … ]
%Lambda: [0.001605722707983 … ]
%Alpha: 1
%DF: [9 9 9 9 9 9 9 9 9 9 9 8 8 8 … ]
%MSE: [0.877111834461079 … ]
%PredictorNames: {}
%UseCovariance: 0
%SE: [0.245298269937858 … ]
%LambdaMinMSE: 0.127250778557508
%Lambda1SE: 0.354082850313371
%IndexMinMSE: 48
%Index1SE: 59
As you can see, PredictorNames: {} is empty, although a few variables were selected!
No idea why. Can someone help me, please?
Accepted Answer
More Answers (0)
Categories
Find more on Call Python from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!