Matlab Modeling Learning Notes 12--logistic regression model __matlab

Source: Internet
Author: User

Logistic regression is a probabilistic nonlinear regression, which is a multivariable analysis method to study the relationship between two classified observation results and some influencing factors. For example, in epidemiological studies, it is often necessary to analyse the quantitative relationship between disease and risk factors, and the effects of confounding factors need to be excluded in order to properly illustrate this relationship. For linear regression analysis, because the variable y is a binary variable (usually 1 or 0), the application condition is not satisfied, especially when all the factors are at low or high level, the Y value of the predicted value may exceed the 0~1 range, and irrational phenomena occur. The logistic regression analysis can solve the above problems better. The basic form of logistic regression model is as follows:

Therefore, the logistic regression problem can be transformed into linear regression problem by using the logarithmic transformation of the variable P according to the form of ln (p/(1-p)), and the regression parameters are solved by the method of multivariate linear regression. For the case where p takes only 0 and 1, in practice it is not a direct return to p, but rather a monotone continuous probability function pi:

At this point the logistic model is:

Then only the original data should be properly mapped, the regression coefficients can be obtained by linear regression method, and then the value of P is obtained according to the mapping relation between π and P.
The following is an example in the book to assess the repayment capacity of the enterprise, the evaluation indicators and evaluation results of the first 20 companies, the remaining 5 companies are required to evaluate. The data are as follows:

The mapping relation of π to P:

Determination of π value:

Matlab code is as follows:

Clear all
CLC
% Data format format
long
Top 20 data
x0=xlsread (' d:\ database area \ Junior \huawei\matlab\11logistic.xls ', ' e4:g23 ');
% all 25 groups of data: validation and regression
xe=xlsread (' d:\ database district \ Junior \huawei\matlab\11logistic.xls ', ' e4:g28 ');
% of the first 20 groups of data values: P
y0=xlsread (' d:\ database area \ Junior \huawei\matlab\11logistic.xls ', ' h4:h23 ');
N=size (y0,1);
The mapping relationship between%π and p for
i=1:n
    if Y0 (i) ==0
        Y1 (i,1) =0.25;
    else
        Y1 (i,1) =0.75;
    End
-end% constructs constant coefficient
x1=ones (Size (x0,1), 1);
X=[x1,x0];
Y=log (y1./(1-y1));
B=regress (y,x);
% Model validation application for
i=1:size (xe,1)
Pai0=exp (b (1) +b (2) *xe (i,1) +b (3) *xe (i,2) +b (4) *xe (i,3))/(1+exp (b (1) +b (2) *xe (i,1) +b (3) *xe (i,2) +b (4) *xe (i,3)));
    if (pai0<=0.5)
        P (i) =0;
    else
        P (i) =1;
End ended% regression result
disp ([' Regression coefficient: ' Num2str (b ') '  ]);
DISP ([' Evaluation result: ' Num2str (P)  '   ]);

MATLAB operating results are as follows:

The first line is the coefficient of regression model in the problem, the regression model can be brought into the model, and the second behavior is the evaluation result.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.