-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
binary model evaluation #20
Comments
This is a function I wrote for some work analysis: model_acc <- function(.data, .model){
preds <- predict(.model, newdata = .data, type = "response")
pred_data <- data_frame(actual = .data$Attn, preds = preds, type = .data$train) %>%
filter(!is.na(preds)) %>%
group_by(type) %>%
arrange(desc(preds)) %>%
mutate(TPR = cumsum(actual) / sum(actual),
FPR = cumsum(1 - actual) / sum(1 - actual)) %>%
summarize(MSE = mean((preds - actual)^2),
AUC = sum(diff(FPR) * na.omit(lead(TPR) + TPR)) / 2,
TPR = mean(preds > .5 & actual == 1),
TNR = mean(preds <= .5 & actual == 0),
LSR = mean(actual * log(preds) + (1 - actual) * log(1 - preds)))
cal <- data_frame(actual = .data$Attn, preds = preds, type = .data$train) %>%
filter(!is.na(preds)) %>%
group_by(type) %>%
mutate(pred_group = cut(preds, breaks = floor(n() / 1000), include.lowest = T)) %>%
group_by(type, pred_group) %>%
summarize(mean_pred = mean(preds), mean_actual = mean(actual)) %>%
summarize(Bias = mean(mean_pred - mean_actual))
return(left_join(pred_data, cal, by = "type")) Positives:
Negatives:
|
To generalize we could probably use formulas, for example the call binary_model_evaluation <- function(.data = model_data, prediction_formula = dependent ~ prediction, group_var = "split") Would tell us that in the |
If we wanted to make the metrics portable we would have to write each as a separate function and then pass the different measures as list or named vector. |
not sure what the output should be
The text was updated successfully, but these errors were encountered: