I am trying to model a Bayesian Network in python using Pomegranate package. The network should be learned from data. So I am using .from_samples method. However I am having trouble using the method .predict_proba() and it gives me error.

This is how I build the model:

model = BayesianNetwork.from_samples(X_train, algorithm='chow-liu')

and this is how I do prediction:

model.predict_proba(X_train)

and this is the error I get:

ValueError: Sample does not have the same number of dimensions as the model. Your help would be highly appreciated.

3

There are 3 best solutions below

0
On

you should use predict() method to predict the state of the not-valued nodes.

Check the documentation for more details. Also, in the repository you can find some interesting tutorials that will help you.

0
On

Please add [] around the sample you are passing

0
On

I got the answer: you should define your state_names when calling the from_samples method.

Another question is how do we do classification using this model?