Vikhyath_11

a6

Dec 12th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #program 6
  2. # import numpy as np
  3. # import csv
  4. import pandas as pd
  5. from pgmpy.models import BayesianNetwork
  6. from pgmpy.estimators import MaximumLikelihoodEstimator
  7. from pgmpy.inference import VariableElimination
  8. heart=pd.read_csv('P6Data.csv')
  9. heart=heart.replace('?',"null")
  10. print(heart.head())
  11. model=BayesianNetwork([('age','target'),('sex','target'),
  12. ('cp','target'),('exang','target'),('target','restecg'),
  13. ('target','chol')])
  14. model.fit(heart,estimator=MaximumLikelihoodEstimator)
  15. heart_infer=VariableElimination(model)
  16. q1=heart_infer.query(variables=['target'],evidence={'age':50})
  17. print(q1)
  18. q2=heart_infer.query(variables=['target'],evidence={'chol':300})
  19. print(q2)
  20.  
Add Comment
Please, Sign In to add comment