counterfactuals icon indicating copy to clipboard operation
counterfactuals copied to clipboard

Classification tasks are sometimes not recognized

Open andreash0 opened this issue 1 year ago • 1 comments

I haven't had time to investigate this in detail, but it seems that there are cases where our classification methods do not correctly recognize classification tasks:

library(counterfactuals)
library(iml)
library(dplyr)
library(tidymodels)

data(german, package = "rchallenge")

credit = german[, c("duration", "amount", "purpose", "age",
                    "employment_duration", "housing", "number_credits", "credit_risk")]

x_interest = credit[998L,]
rf = rand_forest(mode = "classification", engine = "randomForest") %>%
  fit(credit_risk ~ ., data = credit[-998L,])

pred = Predictor$new(model = rf, data = credit[-998L,], y = "credit_risk")
nice_classif = MOCClassif$new(pred)
#> Error in super$initialize(predictor, lower, upper, distance_function): MOCClassif only works for classification tasks.

However, if we explicitely set the prob argument in the Predictor$init() method, it works:

library(counterfactuals)
library(iml)
library(dplyr)
library(tidymodels)
data(german, package = "rchallenge")

credit = german[, c("duration", "amount", "purpose", "age",
                    "employment_duration", "housing", "number_credits", "credit_risk")]

x_interest = credit[998L,]
rf = rand_forest(mode = "classification", engine = "randomForest") %>%
  fit(credit_risk ~ ., data = credit[-998L,])

pred = Predictor$new(model = rf, data = credit[-998L,], y = "credit_risk", type = "prob")
nice_classif = MOCClassif$new(pred)

andreash0 avatar Mar 22 '23 13:03 andreash0