我有一个非常简单的问题,有一个简单的可重复示例,该示例与我使用 bnlearn 进行预测的工作有关
library(bnlearn)
Learning.set4=cbind(c("Yes","Yes","Yes","No","No","No"),c(9,10,8,3,2,1))
Learning.set4=as.data.frame(Learning.set4)
Learning.set4[,c(2)]=as.numeric(as.character(Learning.set4[,c(2)]))
colnames(Learning.set4)=c("Cause","Cons")
b.network=empty.graph(colnames(Learning.set4))
struct.mat=matrix(0,2,2)
colnames(struct.mat)=colnames(Learning.set4)
rownames(struct.mat)=colnames(struct.mat)
struct.mat[1,2]=1
bnlearn::amat(b.network)=struct.mat
haha=bn.fit(b.network,Learning.set4)
#Some predictions with "lw" method
#Here is the approach I know with a SET particular modality.
#(So it's happening with certainty, here for example I know Cause is "Yes")
classic_prediction=cpdist(haha,nodes="Cons",evidence=list("Cause"="Yes"),method="lw")
print(mean(classic_prediction[,c(1)]))
#What if I wanted to predict the value of Cons, when Cause has a 60% chance of being Yes and 40% of being no?
#I decided to do this, according the help
#I could also make a function that generates "Yes" or "No" with proper probabilities.
prediction_idea=cpdist(haha,nodes="Cons",evidence=list("Cause"=c("Yes","Yes","Yes","No","No")),method="lw")
print(mean(prediction_idea[,c(1)]))
以下是帮助内容:
“在离散或有序节点的情况下,也可以提供两个或多个值。在这种情况下,该节点的值将以统一的概率从一组指定值中采样”
当我使用分类变量预测变量的值时,我现在只使用所述变量的某种模态,如示例中的第一个预测。(将证据设置为“是”会使 Cons 获得较高的价值)
但是,如果我想在不确定变量 Cause 的确切模态的情况下预测 Cons,我可以使用我在第二个预测中所做的(只知道概率)吗?这是一种优雅的方式还是有更好的实施方式我不知道?