-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added metric function to package for analysis of experimental predict…
…ions; updated README metrics
- Loading branch information
Showing
13 changed files
with
114 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#' Finds metrics from a table of forecast predictions | ||
#' @param fc tibble of predictions | ||
#' @param predicted_col character string of predicted classification column name | ||
#' @param measured_col character string of measured classification column | ||
#' @export | ||
forecast_metrics <- function(fc, | ||
predicted_col = "predicted_class", | ||
measured_col = "actual_class") { | ||
correct <- fc |> | ||
dplyr::filter(.data[[predicted_col]] == .data[[measured_col]]) |> | ||
nrow() | ||
tn <- fc |> | ||
dplyr::filter(.data[[predicted_col]] != 3 & .data[[measured_col]] != 3) |> | ||
nrow() | ||
tp <- fc |> | ||
dplyr::filter(.data[[predicted_col]] == 3 & .data[[measured_col]] == 3) |> | ||
nrow() | ||
fp <- fc |> | ||
dplyr::filter(.data[[predicted_col]] == 3 & .data[[measured_col]] != 3) |> | ||
nrow() | ||
fn <- fc |> | ||
dplyr::filter(.data[[predicted_col]] != 3 & .data[[measured_col]] == 3) |> | ||
nrow() | ||
|
||
precision <- tp/(tp+fp) | ||
recall <- tp/(tp+fn) | ||
sensitivity <- tp/(tp+fn) | ||
specificity <- tn/(tn+fp) | ||
|
||
f_1 <- (2)*(precision*recall)/(precision+recall) | ||
cl_accuracy <- (tn+tp)/nrow(fc) | ||
accuracy <- correct/nrow(fc) | ||
|
||
metrics_c3 <- dplyr::tibble(tp = tp, | ||
fp = fp, | ||
tn = tn, | ||
fn = fn, | ||
accuracy = accuracy, | ||
cl_accuracy = cl_accuracy, | ||
f_1=f_1, | ||
precision = precision, | ||
sensitivity = sensitivity, | ||
specificity = specificity) | ||
|
||
return(metrics_c3) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.