我正在使用 R 中的 bnlearn 包来预测某些结果。但是,对于我数据集中的所有行,我得到相同的预测。
训练
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)
}
预言
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;
}
HC 和 MMHC 的输出(不同输入的不同预测)
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
GS 的输出(每行的预测相同)
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