1

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

通常当训练模型完全由离散变量组成时,您可以传递pred = TRUEpredict()函数,但混合模型并非如此。我似乎找不到任何有用的文档来说明如何使用混合网络完成此任务(或类似或可比较的内容)。

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
4

0 回答 0