import numpy as np
import csv
import pandas as pd

from pgmpy.model import BayesianModel
from pgmpy.estimators import MaximumLikelihoodEstimator
from pgmpy.interence import VariableElimination
heartDisease=pd.read_csv("C:\\Users\\ISEDSCE\\Desktop\\p6 csv.csv")
heartDisease.heartDisease.replace('?',np.nan)
print('Few example from the dataset are given below')
print(heartDisease.head())
model=BayesianModel([('age','heart disease'),('gender','heart disease'),('exang','heart disease'),('cp','heart disease'),('heart disease','restecg'),('heart disease','chol')])
print("\n learning cpd using maximum likelihood estimators")
model.fit(heartDisease,estimator=MaximumLikelihoodEstimator)
print('\ninterferencing with Bayesian Network')
heartDiseasetest_infer=VariableEliminator(model)
print('\n 1.probability of heart disease given evidance=restecg')
q1=heartDiseasetest_infer.query(variables=['heart disease'],evidance={'age':28})
print(q1)
print('\n 1.probability of heart disease given evidance=cp')
q2=heartDiseaseTest_infer.query(variable=['heart disease'],evidance={'chol'=100})
print(q2)
