4

I tried to train a h2o model using the following code and make a prediction for new data, but it leads to an error. How can I avoid this error?

library(mlr)
a <- data.frame(y=factor(c(1,1,1,1,1,1,1,1,0,0,1,0)), 
                x1=rep(c("a","b","c"), times=c(6,3,3)))
aTask <- makeClassifTask(data = a, target = "y", positive = "1")
h2oLearner <- makeLearner("classif.h2o.deeplearning", 
                          predict.type = "prob")
model <- train(h2oLearner, aTask)

b <- data.frame(x1=rep(c("a","b", "c"), times=c(3,5,4)))
pred <- predict(model, newdata=b)

leads to the following error:

Error in checkPredictLearnerOutput(.learner, .model, p) :
predictLearner for classif.h2o.deeplearning has returned not the class levels as column names: p0,p1

If I change predict.type to "response" it works. So how to predict probabilities?

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
tover
  • 535
  • 4
  • 11
  • Just FYI, I've not seen anyone use mlr (successfully or not) with h2o before. Based on the above, I expect some integration needs to be done for it to work. – TomKraljevic Jul 10 '17 at 17:03
  • Not sure if this comment is still useful now that we know it is due to a bug, but for example this works (on a different computer however, where I needed to update R first): library(mlr) data(iris) iris2 <- iris iris2$Species <- ifelse(iris$Species=="setosa", "ja", "nein") task = makeClassifTask(data = iris2, target = "Species") lrn = makeLearner("classif.h2o.deeplearning", predict.type="prob") model = train(lrn, task) pred = predict(model, newdata=iris2) – tover Jul 10 '17 at 21:09

1 Answers1

3

This bug was fixed in this commit and will be in the next release. Until then, you can install the Github version:

devtools::install_github("mlr-org/mlr")
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204