我在R中使用bnlearn包来预测某些结果。但是,对于我的数据集中的所有行,我得到相同的预测。
培训
<dialog id="login" style="border-color: blue; border: 1px solid">
<form name="reg">
First Name : <input type="text" name="fname" required>
Last Name: <input type="text" name="lname" required>
Email <input type="email" name="mail" required>
Password: <input type="password" name="pass" required>
Confirm Password : <input type="password" name="confpass" required>
<button type="submit"></button>
<button type="reset"></button>
</form>
</dialog>
<script>
function registration(){
var dailog = document.getElementById('login');
dailog.open();
}
</script>
预测
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)
}
HC和MMHC的输出(不同输入的不同预测)
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;
}
GS的输出(每行的预测相同)
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