Open ugroempi opened 4 years ago
Thanks for reporting this issue. Could you add a small reproducible example?
Here is a small example that illustrates the issue (assuming iml and randomForest are loaded).
set.seed(71)
iris.rf <- randomForest(Species ~ ., data=iris)
predictfun <-
function(model, newdata, type="prob"){
### probability for second class
hilf <- predict(model, newdata, type="prob")[,2]
if (type=="prob") return(hilf)
if (type=="logit") {
hilf <- log(hilf/(1-hilf))
hilf[hilf==Inf] <- 999
hilf[hilf==-Inf] <- -999
return(hilf)
}
else return(predict(model, newdata, type=type))
}
predictfun(iris.rf, iris, type="logit")
model <- Predictor$new(iris.rf, iris, predict.fun = predictfun, type="logit")
model$predict(iris)
Hi Christoph,
I may have stumbled on a bug: the documentation for
Predictor
claims that thetype
is handed topredict.fun
, if both are specified. However, I am trying to use apredict.fun
(for a random forest from the randomForest package) with a type argument that does not have a default, and I get the error messageError in (function (object, newdata, type) :
argument "type" is missing, with no default
If I use a default, this default is always used, i.e. changing the
type
argument inPredictor$new
does not change the prediction behavior. I have to hardcode different predictor functions for different types in order to get them to work with iml.Best, Ulrike