civic_metrics: Compute performance metrics for any task type

View source: R/civic_data_utils.R

civic_metricsR Documentation

Compute performance metrics for any task type

Description

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'.

Usage

civic_metrics(y_true, y_pred, y_prob = NULL, positive = NULL, type = "auto")

Arguments

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"'.

Value

A named numeric vector of metrics.

Examples

# 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)

civic.icarm documentation built on June 18, 2026, 1:06 a.m.