bnlear R中的bn.fit预测函数中的错误 [英] Error in bn.fit predict function in bnlear R

查看:99
本文介绍了bnlear R中的bn.fit预测函数中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经学习并在bnlearn R程序包中安装了贝叶斯网络,并且希望预测它的事件"节点值.

I have learned and fitted Bayesian Network in bnlearn R package and I wish to predict it's "event" node value.

fl="data/discrete_kdd_10.txt"
h=TRUE
dtbl1 = read.csv(file=fl, head=h, sep=",")
net=hc(dtbl1)
fitted=bn.fit(net,dtbl1)

我想基于存储在另一个文件中的证据来预测事件"节点的值,该文件的结构与用于学习的文件相同.

I want to predict the value of "event" node based on the evidence stored in another file with the same structure as the file used for learning.

fileName="data/dcmp.txt"
dtbl2 = read.csv(file=fileName, head=h, sep=",")
predict(fitted,"event",dtbl2)

但是,预测失败的原因 Error in check.data(data) : variable duration must have at least two levels.

However, predict fails with Error in check.data(data) : variable duration must have at least two levels.

我不明白为什么证据数据框架中的变量级别数应该受到限制.

I don't understand why there should be any restriction on number of levels of variables in the evidence data.frame.

dtbl2 data.frame仅包含几行,每种情况下我都希望预测事件"值.

The dtbl2 data.frame contains only few rows, one for each scenario in which I want to predict the "event" value.

我知道我可以使用cpquery,但是我也希望对具有混合变量(离散和连续)的网络也使用predict函数.我还没有找到如何在cpqery中使用连续变量的证据.

I know I can use cpquery, but I wish to use the predict function also for networks with mixed variables (both discrete and continuous). I haven't found out how to make use of evidence of continuous variable in cpqery.

有人可以解释一下predict函数在做什么,我该怎么做呢? 预先感谢!

Can someone please explain what I'm doing wrong with the predict function and how should I do it right? Thanks in advance!

推荐答案

问题是读取证据data.frame in

The problem was that reading the evidence data.frame in

fileName="data/dcmp.txt"
dtbl2 = read.csv(file=fileName, head=h, sep=",")
predict(fitted,"event",dtbl2)

使分类变量成为具有不同级别数(原始训练集的水平子集)的因子.

caused categoric variables to be factors with different number of levels (subset of levels of the original training set).

我使用以下代码来解决此问题.

I used following code to solve this issue.

for(i in 1:dim(dtbl2)[2]){
  dtbl2[[i]] = factor(dtbl2[[i]],levels = levels(dtbl1[[i]]))
}

通过bnlearn软件包可以使模型具有混合变量,并且还可以为其中的预测提供功能.

By the way bnlearn package does fit models with mixed variables and also provides functions for predictions in them.

这篇关于bnlear R中的bn.fit预测函数中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆