# How to view the equation of a linear regression model, automatically generated with regression learner

조회 수: 65(최근 30일)
Carolina Hernández 2020년 12월 17일
댓글: Carolina Hernández 2021년 1월 12일
How to view the equation of a linear regression model, automatically generated with regression learner, as the coefficients of the variables and the intercept.

댓글을 달려면 로그인하십시오.

### 채택된 답변

Jule 2021년 1월 7일
Export the model and then open the newly created structure variable from your workspace window. Under 'coefficients' and 'CoefficientNames' there will be a list of the variables and the associated values and 2SD uncertainties for the fit. Note that 'VariableA:VariableB' actually means VariableA * VariableB, but it's written as a division for some weird reason
##### 댓글 수: 1표시 없음숨기기 없음
Carolina Hernández 2021년 1월 12일
Thank you

댓글을 달려면 로그인하십시오.

### 추가 답변(1개)

Abhishek Gupta 2020년 12월 21일
As per my understanding, you want to view the linear regression model equation with coefficients and intercept in it. Below code output the equation in a string format: -
X = [Weight,Horsepower,Acceleration];
mdl = fitlm(X,MPG); % Fit a linear regression model
vars = cat(1, {'1'}, mdl.PredictorNames); % create variable matrix
coeffs = string(mdl.Coefficients.Estimate); % create coeffcients matrix
equation = strcat('y=', strjoin(strcat('(', strcat(strcat(coeffs, '*'), vars), ')'), ' + ')); % output
##### 댓글 수: 1표시 없음숨기기 없음
Carolina Hernández 2021년 1월 12일
Thank you

댓글을 달려면 로그인하십시오.

### 범주

Find more on Linear Regression 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!