-
Notifications
You must be signed in to change notification settings - Fork 1
machine learning exercise
Sébastien LUCAS edited this page Aug 4, 2017
·
1 revision
Fit a linear model on the diamonds dataset predicting price using all other variables as predictors (i.e. price ~ .). Save the result to model. Make predictions using model on the full original dataset and save the result to p. Compute errors using the formula errors=predicted−actualerrors=predicted−actual. Save the result to error. Compute RMSE using the formula you learned in the video and print it to the console.
# Fit lm model: model
model <- lm(price ~ ., diamonds)
# Predict on full data: p
p <- predict(model, diamonds)
# Compute errors: error
error <- p - diamonds[["price"]]
# Calculate RMSE
sqrt(mean(error^2))