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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.