View source: R/helper_functions.R
| calculate_fs_metrics_cv | R Documentation |
Computes TP, FP, FN, TN, Sensitivity, Specificity, Precision, and F1-Score.
calculate_fs_metrics_cv(
selected_vars,
true_vars_global,
total_feature_count_p_val
)
selected_vars |
A character vector of selected variable names. |
true_vars_global |
A character vector of the true variable names. |
total_feature_count_p_val |
The total number of candidate features (p). |
The function handles edge cases where the number of true positives, false positives, or false negatives is zero to avoid division-by-zero errors in precision, sensitivity, and F1-score calculations.
A list containing the following numeric elements:
TP: True Positives
FP: False Positives
FN: False Negatives
TN: True Negatives
Sens: Sensitivity (Recall)
Spec: Specificity
Prec: Precision
F1: F1-Score
N_Selected: Total number of selected variables
Inputs are character vectors; no NA imputation is performed. Division by zero is guarded with 0-valued metrics as documented.
# --- Example for an internal function ---
# Imagine our model selected 3 variables: V1, V2, and V10
selected <- c("V1", "V2", "V10")
# And the "true" important variables were V1, V2, V3, and V4
true_set <- c("V1", "V2", "V3", "V4")
# And the total pool of variables was 50
p <- 50
# Calculate the performance metrics
metrics <- calculate_fs_metrics_cv(
selected_vars = selected,
true_vars_global = true_set,
total_feature_count_p_val = p
)
print(metrics)
#> Expected output:
#> $TP
#> [1] 2
#> $FP
#> [1] 1
#> $FN
#> [1] 2
#> $TN
#> [1] 45
#> $Sens
#> [1] 0.5
#> $Spec
#> [1] 0.9782609
#> $Prec
#> [1] 0.6666667
#> $F1
#> [1] 0.5714286
#> $N_Selected
#> [1] 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.