Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

Time:2022-5-28

Original link:http://tecdat.cn/?p=24777 

Building datasets with redundant predictors and usingLasso and GLMIdentify these predictors.

applylassoRegularization to remove redundant prediction variables

Create aXA random matrix containing 100 observations and 10 prediction variables.yOnly four predictive variables and a small amount of noise are used to create a normally distributed dependent variable.

Default
randn ;

X* weight + randn*0.1; % small additional noise

implementlassoRegularization.

lasso

Find the 75thLambdaCoefficient vector of valuesB

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

lassoglmIdentify and delete redundant predictive variables.

Cross validation of generalized linear modelslassoRegularization

Build data from Poisson model and uselassoIdentify important predictors.

Create data with 20 predictors. Only three predictors plus a constant are used to create the Poisson dependent variable.

RNG% for reproducibility
 randn

exp(X)*weights + 1

Cross validation of Poisson regression model with constructed datalassoRegularization.

Check the cross validation diagram to seeLambdaEffect of regularization parameters.

Plot('CV'); 
legend

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

Green circle and dotted line positioningLambdaThe position where the cross validation error is minimum. The blue circle and dotted line locate the point with the minimum cross validation error plus one standard deviation.

Find the non-zero model coefficients corresponding to the two identification points.

FitInf
find(B

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

FitInf
min1fnd(B)

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

The coefficients from the minimum plus one standard error point are the ones used to create the data.

applylassoRegularized predictor

Load the student test score data set. Convert the last exam result into a logical vector, where1More than 800The score of represents the score below 80.

ynm = (y>=80);

The data is divided into training set and test set.

RNG default% set the seed of repeatability
Xi = X(iTain,:);
yran = yBinom
yTe = yBinom

Perform 3-fold cross validation on the training data and perform regression on the generalized linear modellassoRegularization. Values in assumptionsyIs binomial. Select corresponding toLambdaModel coefficient for the minimum expected deviation.

lasso(Trn,Tain,'binomial','CV',3);
ince = FitIiance;
FitIept

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

Use the model coefficients found in the previous step to predict the test scores of the test data. Use linked functions that specify binomial dependent variables'logit'. Converts the predicted value to a logical vector.

Use the confusion matrix to determine the accuracy of the prediction.

confuhart

Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

This function can correctly predict 31 test scores. However, this function incorrectly predicts that one student will get a grade of B or above and four students will get a grade of B or below.


Lasso of MATLAB generalized linear model GLM Poisson regression, regularization of elastic network, classification, prediction of test score data and visualization of cross validation

Most popular insights

1.Application case of multiple logistic regression in R language

2.Case implementation of panel smooth transition regression (PSTR) analysisAnalysis case implementation “)

3.Partial least squares regression (PLSR) and principal component regression (PCR) in MATLAB

4.Case study of Poisson Poisson regression model in R language

5.Analysis of lung cancer by logistic regression model with mixed effect of R language

6.Implementation of lasso regression, ridge ridge regression and elastic net model in R language

7.R language logistic regression, naive Bayes Bayes, decision tree, random forest algorithm to predict heart disease

8.Prediction of stock price by linear regression in Python

9.R language uses logistic regression, decision tree and random forest to classify and predict credit data sets