How to create a linear regression model

More generally, to create a linear regression model, use the fitlm() function. This function creates a LinearModel object. The object in the workspace has a series of properties that can be immediately viewed by simply clicking on it. Methods such as plot, plotResiduals, and plotDiagnostics are available if you want to create plots and perform a diagnostic analysis.

LinearModel is an object comprising training data, model description, diagnostic information, and fitted coefficients for a linear regression.

By default, fitlm() takes the last variable in the table or dataset array as the response. Otherwise, we have to specify predictors and response variables, for example, as a formula. In addition, ...

Get MATLAB for Machine Learning now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.