pysmile k-fold CV

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

pysmile k-fold CV

Post by liid » Sat Aug 04, 2018 6:36 am


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");
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: 25
Joined: Mon Nov 06, 2017 6:41 pm

Re: pysmile k-fold CV

Post by piotr [BayesFusion] » Tue Aug 07, 2018 7:16 am

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)
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))
Check out docs page:
SMILE Programmer's Manual (C++) page 26
SMILE Wrapper Programmer's Manual (Java, Python, .NET) page 35,37

Post Reply