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