I am using the bnlearn package in R to predict certain outcomes. However, for all rows in my data set, I get the same predictions.
Training
buildModel <- function()
{
#building bn model
#for Hill Climbing, works fine
#hcbn = hc(bndf, blacklist = blacklist, score='bic',restart = 0)
#for Max Min Hill Climbing, also works fine, get different predictions for rows
#hcbn = mmhc(bndf, blacklist = blacklist, optimized=TRUE)
#for Grow Shrink, get the same predictions every row
hcbn = cextend(gs(bndf, blacklist = blacklist, optimized=TRUE))
hcbn.fitted = bn.fit(hcbn, bndf, method='bayes')
hcbn.grain <<- as.grain(hcbn.fitted)
}
Prediction
hcpredthirtyday1[[i]] <- foreach (j = start:min(end, nrow(predictdf)), .combine=rbind) %dopar%
{
predict(hcbn.grain, response = c("myresponse"), newdata = predictdf[j, ], predictors = myypredictors, type = "distribution")$pred$myresponse;
}
Output for HC and MMHC (different predictions for different input)
0 1
[1,] 0.8617731 0.13822686
[2,] 0.8617731 0.13822686
[3,] 0.8617731 0.13822686
[4,] 0.8617731 0.13822686
[5,] 0.8617731 0.13822686
[6,] 0.8617731 0.13822686
[7,] 0.8617731 0.13822686
[8,] 0.8617731 0.13822686
[9,] 0.8617731 0.13822686
[10,] 0.9077158 0.09228421
Output for GS (same predictions for every row)
0 1
[1,] 0.8633219 0.1366781
[2,] 0.8633219 0.1366781
[3,] 0.8633219 0.1366781
[4,] 0.8633219 0.1366781
[5,] 0.8633219 0.1366781
[6,] 0.8633219 0.1366781
[7,] 0.8633219 0.1366781
[8,] 0.8633219 0.1366781
[9,] 0.8633219 0.1366781
[10,] 0.8633219 0.1366781