choose_metric: Choose metric

View source: R/choose_metric.R

choose_metricR Documentation

Choose metric

Description

Extracts metrics from metric_data from fairness object. It allows to visualize and compare parity loss of chosen metric values across all models.

Usage

choose_metric(x, fairness_metric = "FPR")

Arguments

x

object of class fairness_object

fairness_metric

char, single name of metric, one of metrics:

  • TPR - parity loss of True Positive Rate (Sensitivity, Recall, Equal Odds)

  • TNR - parity loss of True Negative Rate (Specificity)

  • PPV - parity loss of Positive Predictive Value (Precision)

  • NPV - parity loss of Negative Predictive Value

  • FNR - parity loss of False Negative Rate

  • FPR - parity loss of False Positive Rate

  • FDR - parity loss of False Discovery Rate

  • FOR - parity loss of False Omission Rate

  • TS - parity loss of Threat Score

  • ACC - parity loss of Accuracy

  • STP - parity loss of Statistical Parity

  • F1 - parity loss of F1 Score

Value

chosen_metric object It is a list with following fields:

  • parity_loss_metric_data data.frame with columns: parity_loss_metric and label

  • metric chosen metric

  • label character, vector of model labels

Examples

data("german")

y_numeric <- as.numeric(german$Risk) - 1

lm_model <- glm(Risk ~ .,
  data = german,
  family = binomial(link = "logit")
)

explainer_lm <- DALEX::explain(lm_model, data = german[, -1], y = y_numeric)

fobject <- fairness_check(explainer_lm,
  protected = german$Sex,
  privileged = "male"
)


cm <- choose_metric(fobject, "TPR")
plot(cm)

rf_model <- ranger::ranger(Risk ~ .,
  data = german,
  probability = TRUE,
  num.trees = 200
)


explainer_rf <- DALEX::explain(rf_model, data = german[, -1], y = y_numeric)

fobject <- fairness_check(explainer_rf, fobject)

cm <- choose_metric(fobject, "TPR")
plot(cm)



ModelOriented/FairModels documentation built on Aug. 30, 2022, 5:48 p.m.