0

I want to use the iml-package calculate permutation feature importance and use logLoss as a loss function.

     mtcars$vs <- as.factor(mtcars$vs)
    rf <- randomForest(vs ~ ., data = mtcars, importance = TRUE)
    X <- mtcars[which(names(mtcars) != "vs")]
    predictor <- Predictor$new(rf, data = X, y = mtcars$vs, type = "prob")
    imp <- FeatureImp$new(predictor, loss = "logLoss")

Unfortunately, I get the error message "Error in Math.factor(predicted): ‘log’ not meaningful for factors" in the last step.

Does somebody know what mistake I have made? Thank you in advance.

koala
  • 5
  • 2
  • from the function it calls, seems like it cannot take a multi-class, https://www.rdocumentation.org/packages/Metrics/versions/0.1.4/topics/logLoss, is that what you are doing? – StupidWolf Nov 05 '20 at 21:01
  • @StupidWolf Yes, that is the loss function I want to use. The target variable (Win_1) is binary and I want to predict probabilities. I used this page as orientation. – koala Nov 05 '20 at 23:34
  • @koala Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It is unclear where your loss function comes from. – pat-s Nov 06 '20 at 16:28
  • @pat-s Thank you for your answer. I have edited the sample code with a reproducible example using the mtcars-dataset. – koala Nov 06 '20 at 18:03

0 Answers0