-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
301 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,5 @@ inst | |
/Meta/ | ||
renv | ||
^\. | ||
.Rprofile | ||
^renv |
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,40 @@ | ||
#' binary_acc | ||
#' | ||
#' @description Calculate the binary class accuracy for a given predicted set of | ||
#' values and corresponding targets | ||
#' | ||
#' @param preds Predicted label or predicted probability between 0 and 1, | ||
#' same shape as target label | ||
#' @param target Target label | ||
#' @param threshold The numerical cut-off between 0 and 1 to transform | ||
#' predicted probability into binary predicted labels | ||
#' @param multidim_average Average model: global-average across all accuracies, | ||
#' samplewise-average across the all but the first dimensions (calculated | ||
#' independently for each sample) | ||
#' | ||
#' @return Binary accuracy for preds and target, with format dictated by | ||
#' multidim_average command. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' binary_acc(c(0.8, 0.2), c(1,1), 0.3) | ||
#' binary_acc(c(1,1), c(0,1)) | ||
binary_acc <- function(preds, target, threshold=0.5, multidim_average = "global"){ | ||
|
||
stopifnot(dim(preds)==dim(target)) | ||
|
||
# transform probability into labels if necessary | ||
if(is.numeric(preds)&(!is.integer(preds))){ | ||
preds <- as.numeric(preds>threshold) | ||
} | ||
|
||
cfs_mtx <- confusion_scores(preds, target, multidim_average) | ||
|
||
if(multidim_average == "global"){ | ||
return(sum(diag(cfs_mtx$matrix))/sum(cfs_mtx$matrix)) | ||
} | ||
else{ | ||
return((cfs_mtx$tp+cfs_mtx$tn)/(cfs_mtx$tp+cfs_mtx$tn+cfs_mtx$fn+cfs_mtx$fp)) | ||
} | ||
} |
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,38 @@ | ||
#' binary_precision | ||
#' | ||
#' @description Calculate the binary classtypeification precision for a given predicted set of | ||
#' values and corresponding targets. In other words, this function estimate how accurate | ||
#' the true prediction value by the model is. | ||
#' | ||
#' @param preds Predicted labels or predicted probability between 0 and 1, | ||
#' same shape as target label | ||
#' @param target Target label | ||
#' @param threshold The numerical cut-off between 0 and 1 to transform | ||
#' predicted probability into binary predicted labels | ||
#' @param multidim_average Average model: global-average across all accuracies, | ||
#' samplewise-average across the all but the first dimensions (calculated | ||
#' independently for each sample) | ||
#' | ||
#' @return Binary precision value for preds and target, with format dictated by | ||
#' multidim_average command. | ||
#' | ||
#' @export | ||
#' | ||
#' @examples | ||
#' binary_precision(c(0.8, 0.2), c(1,1), 0.3) | ||
#' binary_precision(c(1,1), c(0,1)) | ||
binary_precision <- function(preds, target, threshold=0.5, multidim_average = "global"){ | ||
|
||
stopifnot(dim(preds)==dim(target)) | ||
|
||
# transform probability into labels when necessary | ||
if(is.numeric(preds)&(!is.integer(preds))){ | ||
preds <- as.numeric(preds>=threshold) | ||
} | ||
|
||
cfs_mtx <- confusion_scores(preds, target, multidim_average) | ||
if(any((cfs_mtx$tp+cfs_mtx$fp==0))){ | ||
warning("NaN generated due to lack of positively predicted labels") | ||
} | ||
return((cfs_mtx$tp)/(cfs_mtx$tp+cfs_mtx$fp)) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.