# NOT RUN {
data('adult.data')
adult.data$income = ifelse(test = adult.data$income == '>50K',
yes = 1, no = 0)
adult.data = adult.data[, colnames(adult.data) %in%
c('age', 'education', 'sex',
'income', 'capital_gain')]
adult.data = adult.data[sample(1:nrow(adult.data), size = 100, replace = FALSE), ]
##### Logistic Regression
if (!requireNamespace("stats", quietly = TRUE)) {
stop("Package \"stats\" needed for this example to work.",
call. = FALSE)}
mod = glm(formula = income ~., data = adult.data, family = binomial(link = 'logit'))
### The 'predict' function returns the classes probabilities
### automatically for caret (package) models
pred = data.frame(greater = mod$fitted.values, less = 1 - mod$fitted.values, sex = adult.data$sex,
classification = ifelse(mod$fitted.values >= 0.5, 'greater', 'less'))
theta = 0.6
pred_changed = roc_method(pred_mod = pred, positive_col = 'greater',
positive_class = 'greater', negative_col = 'less',
sensible_col = 'sex', privileged_group = 'Male',
classification_col = 'classification',
theta = theta)
pred_changed
# }
Run the code above in your browser using DataLab