Live Prediction Example
# Example prediction for a 1.5 carat, Ideal cut, F color, VS1 clarity diamond
new_diamond <- data.frame(
carat = 1.5,
cut = factor("Ideal", levels = c("Fair", "Good", "Very Good", "Premium", "Ideal")),
color = factor("F", levels = c("D", "E", "F", "G", "H", "I", "J")),
clarity = factor("VS1", levels = c("FL", "IF", "VVS1", "VVS2", "VS1", "VS2", "SI1", "SI2", "I1"))
)
prediction <- predict(price_model, new_diamond, interval = "prediction")
cat("Predicted Price: $", round(prediction[1], 0), "\n")
## Predicted Price: $ 11196
cat("95% Confidence Interval: $", round(prediction[2], 0), " - $", round(prediction[3], 0))
## 95% Confidence Interval: $ 8928 - $ 13464
Model Validation
# Model residuals plot
plot(price_model$fitted.values, price_model$residuals,
main = "Model Residuals vs Fitted Values",
xlab = "Fitted Values", ylab = "Residuals",
pch = 16, alpha = 0.5)
abline(h = 0, col = "red", lwd = 2)
