Skip to content

machine learning exercise

Sébastien LUCAS edited this page Aug 4, 2017 · 1 revision

https://campus.datacamp.com/courses/machine-learning-toolbox/regression-models-fitting-them-and-evaluating-their-performance?ex=3

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))

WIKI by Sébastien Lucas CEO & Funder or Bricks

Clone this wiki locally