pysmile k-fold CV

The engine.
Post Reply
liid
Posts: 32
Joined: Tue Jun 19, 2018 5:19 am

pysmile k-fold CV

Post by liid »

Hi,

Just started using pysmile (was using only GeNle so far, but reached to a point where I need some bigger scale network). I have two questions and will be very grateful if you can answer :

1. I am trying to understand how to perform a simple k-fold CV in pysmile. This topic is not included in the wrappers tutorial.
What I need to is pretty much what the following code does, only for pysmile:

DSL_dataset ds;
DSL_network net;
vector<DSL_datasetMatch> matching;
// load network and dataset, create the matching here
DSL_validator validator(ds, net, matching);
int classNodeHandle = net.FindNode("someNodeIdentifier");
validator.AddClassNode(classNodeHandle);
DSL_em em;
// optionally tweak the EM options here
int res = validator.KFold(em, 5);
if (DSL_OKAY == res)
{
double acc;
validator.GetAccuracy(classNodeHandle, 0, acc);
printf("Accuracy=%f\n", acc);
}

Can you please provide a short description about doing CV in pysmile? if not, can you please provide a reference to a document that explains it?

2. I need to create a pretty large cpt (30-50 binary parents) threw pysmile, and I am not sure about the order in which the probabilities should appear in the array. For example, for a ternary node with two binary parents, can you please explain in what order should the 12 probabilities appear?

Thanks a lot!
piotr [BayesFusion]
Site Admin
Posts: 60
Joined: Mon Nov 06, 2017 6:41 pm

Re: pysmile k-fold CV

Post by piotr [BayesFusion] »

1.
I'm assuming, that you initialized dataset and network properly (as ex. ds and net).

Code: Select all

node_id = "someNodeIdentifier"
matching = ds.match_network(net)
validator = pysmile.Validator(net, ds, matching)
validator.add_class_node(node_id)
em = pysmile.Learning.EM()
em.learn(ds, net, matching)
validator.k_fold(em, 5)
acc = validator.get_accuracy(node_id, 0)
print("Accuracy=" + str(acc))
2.
Check out docs page: https://support.bayesfusion.com/docs/
SMILE Programmer's Manual (C++) page 26
SMILE Wrapper Programmer's Manual (Java, Python, .NET) page 35,37
Yang Yajie
Posts: 34
Joined: Thu Mar 19, 2020 11:49 am

Re: pysmile k-fold CV

Post by Yang Yajie »

i modify my code, but i get the results "Accuracy=nan". What is the "nan" mean? (the ...2659.png shows the results)what kind of results represent the network is good after the validation? My file.xdsl is a DBN network.
besides that, i use my another nodes like "Marriage_status", I get the errno=-30 (the ...3447.png shows the results). Could you please tell me why? Did i do something wrong?
Attachments
WeChat Image_20200720203447.png
WeChat Image_20200720203447.png (195.96 KiB) Viewed 5734 times
WeChat Image_20200720202659.png
WeChat Image_20200720202659.png (147.24 KiB) Viewed 5734 times
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: pysmile k-fold CV

Post by shooltz[BayesFusion] »

SMILE does not support validation (including k-fold) in DBNs. You need to unroll your network and run k-fold on the non-DBN model.
Yang Yajie
Posts: 34
Joined: Thu Mar 19, 2020 11:49 am

Re: pysmile k-fold CV

Post by Yang Yajie »

i make a simple BBN network, the network type as shown in picture 4314.png. and use the corresponding data, as shown in aa.csv. but the resutls is "nan". could you please tell me why? and what kind of results represent the network is good after validation?
Attachments
WeChat Image_20200722104314.png
WeChat Image_20200722104314.png (34.23 KiB) Viewed 5715 times
validatorWeChat Image_20200722103759.png
validatorWeChat Image_20200722103759.png (110.8 KiB) Viewed 5715 times
aa.csv
(381 Bytes) Downloaded 285 times
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: pysmile k-fold CV

Post by shooltz[BayesFusion] »

Can you share your "validator test.xdsl" file so we can reproduce the problem?
Post Reply