I would like to understand the meaning of the value (result) of h2o.predict() function from H2o R-package. I realized that in some cases when the predict
column is 1
, the p1
column has a lower value than the column p0
. My interpretation of p0
and p1
columns refer to the probabilities for each event, so I expected when predict=1
the probability of p1
should be higher than the probability of the opposite event (p0
), but it doesn't occur always as I can show in the following example: using prostate dataset.
Here is executable example:
library(h2o)
h2o.init(max_mem_size = "12g", nthreads = -1)
prostate.hex <- h2o.importFile("https://h2o-public-test-data.s3.amazonaws.com/smalldata/prostate/prostate.csv")
prostate.hex$CAPSULE <- as.factor(prostate.hex$CAPSULE)
prostate.hex$RACE <- as.factor(prostate.hex$RACE)
prostate.hex$DCAPS <- as.factor(prostate.hex$DCAPS)
prostate.hex$DPROS <- as.factor(prostate.hex$DPROS)
prostate.hex.split = h2o.splitFrame(data = prostate.hex,
ratios = c(0.70, 0.20, 0.10), seed = 1234)
train.hex <- prostate.hex.split[[1]]
validate.hex <- prostate.hex.split[[2]]
test.hex <- prostate.hex.split[[3]]
fit <- h2o.glm(y = "CAPSULE", x = c("AGE", "RACE", "PSA", "DCAPS"),
training_frame = train.hex,
validation_frame = validate.hex,
family = "binomial", nfolds = 0, alpha = 0.5)
prostate.predict = h2o.predict(object = fit, newdata = test.hex)
result <- as.data.frame(prostate.predict)
subset(result, predict == 1 & p1 < 0.4)
I get the following output for the result of the subset
function:
predict p0 p1
11 1 0.6355974 0.3644026
17 1 0.6153021 0.3846979
23 1 0.6289063 0.3710937
25 1 0.6007919 0.3992081
31 1 0.6239587 0.3760413
For all the above observations from test.hex
dataset the prediction is 1
, but p0 > p1
.
The total observation where predict=1
but p1 < p0
is:
> nrow(subset(result, predict == 1 & p1 < p0))
[1] 14
On contrary there are no predict=0
where p0 < p1
> nrow(subset(result, predict == 0 & p0 < p1))
[1] 0
Here is the table for table
information for predict
:
> table(result$predict)
0 1
18 23
We are using as a decision variable CAPSULE
with the following values:
> levels(as.data.frame(prostate.hex)$CAPSULE)
[1] "0" "1"
Any suggestion?
Note: The question with a similar topic: How to interpret results of h2o.predict does not address this specific issue.