Machine Learning and Data Science: An Introduction to Statistical Learning Methods with R by Daniel Gutierrez

Machine Learning and Data Science: An Introduction to Statistical Learning Methods with R by Daniel Gutierrez

Author:Daniel Gutierrez [Gutierrez, Daniel]
Language: eng
Format: azw3, epub
Publisher: Technics Publications
Published: 2015-09-26T04:00:00+00:00


Figure 5-1 Scatterplot of the linear regression model for medv and rm with regression line

Now you can use the coefficients and the trained model to make predictions for new data (not data from the Boston data set). Let’s say you want to predict the median home value based on the average number of rooms—6, in this case. In the line of code below, we extract out the first coefficient using coef(lm1)[1] and add to it the second coefficient coef(lm1)[2] multiplied by 6. Here, we see the predicted median home value is $19,942.

> coef(lm1)[1] + coef(lm1)[2]*6

(Intercept)

19.94203

Here is another way of making a prediction, this time using the predict() function for the linear model lm1. We need to pass a data frame as an argument containing the rm value of 6. We get the same predicted median home value as before.

> newdata <- data.frame(rm=6)

> predict(lm1, newdata)

1

19.94203



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.