簡體   English   中英

嘗試使用bnlearn包進行預測時出錯 - 貝葉斯網絡

[英]Error while trying to do a prediction with bnlearn package - Bayesian network

我正在嘗試使用bnlearn包做一個預測模型,但是我得到錯誤指示:“check.data(數據)出錯:數據丟失”。 這是我用來預測模型的示例數據集和代碼行:

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)

以下是我用於獲取預測的代碼行:

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."

任何想法如何解決?

預測(fitsbn,node =“要預測的列名”,data = testdata)對我有用

我沒有安裝bnlearn ,但是從你的代碼中我猜測問題是你沒有將輸出(這是類別列)提供給訓練集。 更改:

   training.set = dat[1:8,]

看看它是否有效

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM