library("mlr3")
# Get adult data as a data.table
train = tsk("adult_train")$data()
mod = rpart::rpart(target ~ ., train)
# Predict on test data
test = tsk("adult_test")$data()
yhat = predict(mod, test, type = "vector")
# Convert to a factor with the same levels
yhat = as.factor(yhat)
levels(yhat) = levels(test$target)
compute_metrics(
data = test,
target = "target",
prediction = yhat,
protected_attribute = "sex",
metrics = msr("fairness.acc")
)
Run the code above in your browser using DataLab