Case Study

Bayes’ Law in Heart Failure Data
March 2022

Skills/Tools: Phyton (numpy, pandas, matplotlib, seaborn, networkx)

Just Another Practice


We will use the Heart Failure Dataset. This dataset has 12 attributes, including HeartDisease. 


This work aims to find the causal inferences between medical condition attributes in the dataset and the heart disease class. We define medical condition attributes as all attributes except age and sex.

Bayes’ Law Analysis

We will analyze causal inferences of 720 rows of cleaned* Heart Failure Data using Bayes’ Law.

1. ChestPainType

P(ASY|HeartDisease) > P(NAP|HeartDisease) > P(ATA|HeartDisease) > P(TA|HeartDisease)

P(ASY|HeartDisease) > P(HeartDisease|ASY)

2. FastingBS

P(HeartDisease|FastingBS) > P(FastingBS|HeartDisease)

3. RestingECG

P(HeartDisease|LVH) > P(LVH|HeartDisease)
P(HeartDisease|ST) > P(ST|HeartDisease)

4. ExerciseAngina

P(HeartDisease|ExerciseAngina) > P(ExerciseAngina|HeartDisease)

5. ST_Slope

P(Flat|HeartDisease) > P(Up|HeartDisease) > P(Down|HeartDisease)
P(HeartDisease|Down) > P(Down|HeartDisease)

6. RestingBP

P(HeartDisease|>130) > P(>130|HeartDisease)

7. Cholesterol

P(HeartDisease|>235) > P(>235|HeartDisease)

8. MaxHR

P(>140|HeartDisease) > P(HeartDisease|>140)

9. Oldpeak

P(>0.4|HeartDisease) > P(HeartDisease|>0.4)


dfVis = pd.DataFrame({ 'from': ['heart\ndisease', 'TA\nchestpain', 'fasting\nblood sugar\n>= 120mg/dl', 'LVH\nresting ECG\nresult', 'ST\nresting ECG\nresult', 'exercise-\ninduced\nangina','down-slope of\nthe peak exercise\nST segment','resting\nblood pressure\n> 130mmHg', 'cholesterol\nlevel\n> 235mm/dl', 'heart\ndisease', 'heart\ndisease'],
                       'to': ['ASY\nchestpain', 'heart\ndisease', 'heart\ndisease', 'heart\ndisease', 'heart\ndisease', 'heart\ndisease','heart\ndisease', 'heart\ndisease', 'heart\ndisease','maximum\nheart rate\n> 140', 'oldpeak\n> 0.4']})
G = nx.from_pandas_edgelist(dfVis, 'from', 'to', create_using=nx.DiGraph())

plt.figure(figsize=(8, 8))
nx.draw(G, with_labels = True, node_size = 6000, node_color = 'papayawhip', 
        pos = nx.circular_layout(G), arrows = True, font_size = 11)
plt.title('Causal Inferences Using Bayes\' Law on Heart Failure Data')
*Please see this notebook for the complete cleaning process and analysis.