sambofra / bnstruct

R package for Bayesian Network Structure Learning
GNU General Public License v3.0
17 stars 11 forks source link

Cross validation #26

Closed peterscott1980 closed 5 months ago

peterscott1980 commented 2 years ago

Hi Is there an option in bnstruct to predict network outputs and determine network sensitivity using cross-validation or a similar approach? Alternatively, can I convert the BN network Bayesian networks that are made in bnstruct into networks that can be read by another package like bnclassify or bnlearn so I can do cross-validation and predictions?

If possible please forward or publish some example code for categorical variables.

Kind Regards, Peter

albertofranzin commented 2 years ago

Hello Peter,

bnstruct does not include cross-validation for the network output. You could probably use bootstrap to implement a similar procedure by yourself, but natively there is no method that does this.

I honestly don't know which formats other packages are using, but bnstruct uses its own objects so I would say they are not compatible. However, you can save the dag of a network (it's a matrix), and import it later, I'm sure there is a way of making it work in bnlearn or bnclassify, though I don't know how. You will need to do the parameter learning again, but it's not a problem, computationally speaking.

Categorical variables just need to be translated into numbers. For example, you can use factors for this. Assuming a is going to be a column of your dataset:

> a <- c("True","True","True","False","False","True")
> b <- factor(a)
> b
[1] True  True  True  False False True 
Levels: False True
> as.integer(b)
[1] 2 2 2 1 1 2

Hope this helps.

Alberto