bnlearn:从网络连续预测变量和离散结果中提取概率估计

时间:2019-07-20 04:16:03

标签: r bnlearn

我正在尝试建立一个分类网络,在该网络中,我需要基于大量连续的预测变量来预测分类/离散结果。我可以在学习模型后预测班级,但是有没有办法提取与每个预测班级相关的概率?

通常,当训练后的模型完全由离散变量组成时,可以将pred = TRUE传递给predict()函数,但对于混合模型则不是这种情况。我似乎找不到任何有用的文档来说明如何通过混合网络来完成此任务(或类似或类似的任务)。

library(bnlearn)

# Create learning data ----
train <- data.frame(matrix(runif(13600), ncol = 136, nrow = 100))
train <- cbind(train, data.frame(class = rep(c("one","two","three","four"), 25)))

# Create test data ----
test <- data.frame(matrix(runif(1360), ncol = 136, nrow = 16))
test <- cbind(test, data.frame(class = rep(c("one","two","three","four"), 4)))
# m$class = rep(c("one","two","three","four"), 4)

# Create network
train_network <- mmhc(train)
train_fit = bn.fit(train_network, train)

# Make predictions
pred <- predict(train_fit, "class", method = "bayes-lw", data = test)

pred_df <- cbind(pred, data.frame(actual = test[, "class"]))
head(pred_df)

pred actual
1   one    one
2   one    two
3   two  three
4   one   four
5 three    one
6  four    two

理想情况下,我将能够获得每次观察的预测概率,例如

pred actual prob
1   one    one  0.67
2   one    two  0.44
3   two  three  0.32
4   one   four  0.10
5 three    one  0.11
6  four    two  0.55

0 个答案:

没有答案