machine learning exercise - sinsunsan/archiref_wiki GitHub Wiki
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"](/sinsunsan/archiref_wiki/wiki/"price")
# Calculate RMSE
sqrt(mean(error^2))