View source: R/civic_data_utils.R
| civic_metrics | R Documentation |
Returns a named numeric vector of performance metrics appropriate for the task. Task is inferred automatically unless 'type' is given.
**Binary / multi-class classification metrics:** 'accuracy', 'balanced_acc', 'f1', 'precision', 'recall', 'specificity' (binary only), 'auc' (binary only, requires 'pROC').
**Regression metrics:** 'mae', 'rmse', 'r2'.
civic_metrics(y_true, y_pred, y_prob = NULL, positive = NULL, type = "auto")
y_true |
True outcome values (factor or numeric). |
y_pred |
Predicted values (factor/character for classification, numeric for regression). |
y_prob |
Numeric probability vector for the **positive** class (binary classification only). Used to compute AUC. |
positive |
Character. Positive class level (binary classification). Defaults to first factor level. |
type |
One of '"auto"' (default), '"binary"', '"multiclass"', or '"regression"'. |
A named numeric vector of metrics.
# Classification
y <- factor(c("yes","no","yes","yes","no","no"))
yhat <- factor(c("yes","no","no","yes","no","yes"))
civic_metrics(y, yhat, positive = "yes")
# Regression (any numeric target)
y2 <- c(10, 20, 30, 40, 50)
yhat2 <- c(12, 18, 33, 39, 48)
civic_metrics(y2, yhat2)
# Works with iris
m <- civic_fit(Species ~ ., iris)
yhat3 <- predict(m, iris)
civic_metrics(iris$Species, yhat3)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.