Assessing linear regression models
We'll once again use the lm()
function to fit linear regression models to our data. For both of our datasets, we'll want to use all the input features that remain in our respective data frames. R provides us with a shorthand to write formulas that include all the columns of a data frame as features, excluding the one chosen as the output. This is done using a single period, as the following code snippets show:
> machine_model1 <- lm(PRP ~ ., data = machine_train) > cars_model1 <- lm(Price ~ ., data = cars_train)
Training a linear regression model may be a one-line affair once we have all our data prepared, but the important work comes straight after, when we study our model in order to determine how well we did. ...
Get Mastering Predictive Analytics with R - Second Edition 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.