-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheda.py
More file actions
69 lines (58 loc) · 2.68 KB
/
eda.py
File metadata and controls
69 lines (58 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.figure_factory as ff
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
# Load dataset
df = pd.read_csv("https://raw.github.com/Shubham-S151/CVD-Risk-Predictor/main/Heart%20Disease%20Data.csv.gz")
st.title("Cardiovascular Disease Analysis")
# Display dataset
st.subheader("Dataset Preview")
st.dataframe(df.head())
st.subheader("Missing Values")
st.write(df.isnull().sum())
# Pie Chart for Heart Disease Distribution
st.subheader("Heart Disease Distribution")
fig_pie = px.pie(df, names='Heart_Disease', title='Distribution of Heart Disease',
color_discrete_sequence=['lightgreen', 'red'])
st.plotly_chart(fig_pie)
# Correlation Heatmap
st.subheader("Correlation Heatmap")
corr = df.select_dtypes(include=['number']).corr()
fig_heatmap = ff.create_annotated_heatmap(z=corr.values, x=list(corr.columns), y=list(corr.index),
colorscale='RdBu', showscale=True)
st.plotly_chart(fig_heatmap)
# KDE Plots for Numerical Features
st.subheader("KDE Plots for Numerical Features")
num_cols = df.select_dtypes(include=['number']).columns.tolist()
for col in num_cols:
fig_kde = px.histogram(df, x=col, nbins=50, marginal='box', opacity=0.6,
title=f'Distribution of {col}', color_discrete_sequence=['blue'])
st.plotly_chart(fig_kde)
# Box Plots for Outliers
st.subheader("Box Plots for Numerical Features")
for col in num_cols:
fig_box = px.box(df, y=col, title=f'Boxplot of {col}', color_discrete_sequence=['orange'])
st.plotly_chart(fig_box)
# Count Plots for Categorical Features
st.subheader("Categorical Feature Distribution")
cat_cols = df.select_dtypes(include=['object']).columns.tolist()
for col in cat_cols:
fig_count = px.bar(df[col].value_counts().reset_index(), x='index', y=col,
title=f'Count Plot of {col}', color_discrete_sequence=['green'])
st.plotly_chart(fig_count)
# Bivariate Analysis - Box Plots
st.subheader("Bivariate Analysis: Numerical Features vs Heart Disease")
for col in num_cols:
fig_bivar = px.box(df, x='Heart_Disease', y=col, title=f'{col} vs Heart Disease')
st.plotly_chart(fig_bivar)
# Bivariate Analysis - Categorical Features vs Heart Disease
st.subheader("Bivariate Analysis: Categorical Features vs Heart Disease")
for col in cat_cols:
if col != 'Heart_Disease':
cross_tab = df.groupby([col, 'Heart_Disease']).size().reset_index(name='count')
fig_cat_bivar = px.bar(cross_tab, x=col, y='count', color='Heart_Disease',
title=f'{col} vs Heart Disease', barmode='group')
st.plotly_chart(fig_cat_bivar)