How can I order an inference result using bnlearn in Python?

303 views Asked by At

So, I'm using the Python bnlearn package and when you make the inference a table with probabilistic data is returned. The problem is that I have a lot of data and it would be more interesting if the table were ordered descending. I have no idea how to manipulate that. The class of the 'table' is pgmpy.factors.discrete.DiscreteFactor.DiscreteFactor.

This is how the table looks like

Is it possible to manipulate?

1

There are 1 answers

0
angelrm On

The source code of pgmpy.factors.discrete.DiscreteFactor.DiscreteFactor indicates that the possible values of the variable are stored in the state_names member dictionary, and the actual probabilities in the values member as a numpy array. You can order with a clause similar to

sorted(zip(your_discrete_factor_object.state_names["your variable name"], your_discrete_factor_object.values.tolist()), key = lambda p: p[1])