Python Code:
import pgmpy.models
import pgmpy.inference
import networkx as nx
import pylab as plt
model = pgmpy.models.BayesianModel([('Guest', 'Monty'), ('Price', 'Monty')])
cpd_guest = pgmpy.factors.discrete.TabularCPD('Guest', 3, [[0.33, 0.33, 0.33]])
cpd_price = pgmpy.factors.discrete.TabularCPD('Price', 3, [[0.33, 0.33, 0.33]])
cpd_monty = pgmpy.factors.discrete.TabularCPD('Monty', 3, [[0, 0, 0, 0, 0.5, 1, 0, 1, 0.5],
[0.5, 0, 1, 0, 0, 0, 1, 0, 0.5],
[0.5, 1, 0, 1, 0.5, 0, 0, 0, 0]],
evidence=['Guest', 'Price'],
evidence_card=[3, 3])
model.add_cpds(cpd_guest, cpd_price, cpd_monty)
model.check_model()
print('Probability distribution, P(Guest)')
print(cpd_guest)
print()
print('Probability distribution, P(Price)')
print(cpd_price)
print()
print('Joint probability distribution, P(Monty | Guest, Price)')
print(cpd_monty)
print()
nx.draw(model, with_labels=True)
plt.savefig('Data.png')
plt.close()
infer = pgmpy.inference.VariableElimination(model)
posterior_probability = infer.query(['Price'], evidence={'Guest': 0, 'Monty': 2})
print('Posterior probability, Guest(0) and Monty(2)')
print(posterior_probability)
print()
Output: