How to view the equation of a linear regression model, automatically generated with regression learner
40 ビュー (過去 30 日間)
古いコメントを表示
How to view the equation of a linear regression model, automatically generated with regression learner, as the coefficients of the variables and the intercept.
0 件のコメント
採用された回答
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 件)
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: -
load carsmall % Load the carsmall data set
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
参考
カテゴリ
Help Center および File Exchange で Linear and Nonlinear Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!