How to view the equation of a linear regression model, automatically generated with regression learner
Mostra commenti meno recenti
How to view the equation of a linear regression model, automatically generated with regression learner, as the coefficients of the variables and the intercept.
Risposta accettata
Più risposte (1)
Abhishek Gupta
il 21 Dic 2020
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
1 Commento
Carolina Hernández
il 12 Gen 2021
Categorie
Scopri di più su Linear Regression in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!