How can I use the Lasso to apply to Logistic Regression?

조회 수: 49 (최근 30일)
Cheng-Yu Hsieh
Cheng-Yu Hsieh 2021년 8월 29일
답변: Kumar Pallav 2021년 9월 2일
I am trying to apply supervised binary classification problem with the help of lasso to prevent overfitting. But I am stuck at how to apply lasso to logistic classification function, and how to predict the response values.
Below is the code, where:
  • grpTrain_Lasso: a vector of values 1's & 2's, representing 2 categories.
  • grpTrain_Lasso_categorical: containing 2 categories: "Cancer", "Normal".
  • grpTrain: Original categorical vector, containing the diagnosis of each patient. ("Cancer", "Normal")
  • obsSmall: 195x100, where columns are # of patients records, rows are # of features variables.
Lasso Embedded Model Training
[grpTrain_Lasso grpTrain_Lasso_categorical] = grp2idx(grpTrain)
lModel = lasso(obsSmall, grpTrain_Lasso, "CV", 20)
% column: predictor
% row: lambda value for each parameter (for the predictor)

채택된 답변

Kumar Pallav
Kumar Pallav 2021년 9월 2일
You can use 'lassoglm' function for lasso regularization of generalized linear models including logistic regression.
Refer this example which shows how to regularize binomial regression.
To know more about lassoglm function,you can refer this.

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by