Skip to content

Instantly share code, notes, and snippets.

@lissahyacinth
Created September 4, 2017 09:23
Show Gist options
  • Save lissahyacinth/c5dd8a83eb623d8ae89c871977e3534a to your computer and use it in GitHub Desktop.
Save lissahyacinth/c5dd8a83eb623d8ae89c871977e3534a to your computer and use it in GitHub Desktop.
Return default graphs you'd expect from LM but with custom eresults
get_resid_map <- function(model, test_data, test_col){
prediction <- predict(model, test_data)
test_data_col = test_data[[test_col]]
sprintf("MAPE is %s", MAPE(actual = test_data_col, predicted = prediction))
frame = data.frame(predicted = prediction, actual = test_data_col)
frame$diff = frame$predicted - frame$actual
frame$absdiff = abs(frame$predicted - frame$actual)
return(list(
mape = sprintf("MAPE is %s", MAPE(actual = test_data_col, predicted = prediction)),
pva = ggplot(data = frame, aes(x = predicted, y = actual)) + geom_jitter() + ggtitle("Predicted v Actuals"),
pvd = ggplot(data = frame, aes(x = predicted, y = diff)) + geom_jitter() + ggtitle("Predicted v Diff"),
avd = ggplot(data = frame, aes(x = actual, y = diff)) + geom_jitter() + ggtitle("Actuals v Diff"),
aavd =ggplot(data = frame, aes(x = actual, y = absdiff)) + geom_jitter() + ggtitle("Actuals v Abs.Diff")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment