[英]Error while trying to do a prediction with bnlearn package - Bayesian network
I'm trying to do a prediction model with bnlearn package but I get error indicating : "Error in check.data(data) : the data are missing". 我正在尝试使用bnlearn包做一个预测模型,但是我得到错误指示:“check.data(数据)出错:数据丢失”。 Here is my example data set and line of codes that I used to preformed the prediction model:
这是我用来预测模型的示例数据集和代码行:
dat <- read.table(text = " category birds wolfs snakes
yes 3 9 7
no 3 8 4
no 1 2 8
yes 1 2 3
yes 1 8 3
no 6 1 2
yes 6 7 1
no 6 1 5
yes 5 9 7
no 3 8 7
no 4 2 7
notsure 1 2 3
notsure 7 6 3
no 6 1 1
notsure 6 3 9
no 6 1 1 ",header = TRUE)
Here are the lines of code that I used to get the prediction: 以下是我用于获取预测的代码行:
dat$birds<-as.numeric(dat$birds)
dat$wolfs<-as.numeric(dat$wolfs)
dat$snakes<-as.numeric(dat$snakes)
training.set = dat[1:8,2:4 ]
demo.set = dat[8:16,2:4 ]
res <- hc(training.set)
fitted = bn.fit(res, training.set)
pred = predict(fitted, demo.set) # I get an error: "Error in check.data(data) : the data are missing."
Any Idea how to solve it ? 任何想法如何解决?
预测(fitsbn,node =“要预测的列名”,data = testdata)对我有用
I don't have bnlearn
installed, but from your code I guess that the problem is that you didn't provide the output (which is the category column) into the training set. 我没有安装
bnlearn
,但是从你的代码中我猜测问题是你没有将输出(这是类别列)提供给训练集。 Change: 更改:
training.set = dat[1:8,]
and see if it works. 看看它是否有效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.