Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
173214c
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
093bfea
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
5adc54d
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
da4d471
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
7a64f70
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
ce80c72
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
f77c2ce
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
7a7ca3a
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
a323335
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
b27df32
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
62e524d
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
df65005
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
d7f9774
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
9b7402f
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
054f15c
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
0cb571a
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
8e6ab3c
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
340df84
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
85eddb8
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
a41fe01
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
4ff6a56
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
75630e8
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
75b94e0
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
4b4daa7
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
c008a76
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
252d6dd
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
572257c
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
1400648
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
f3edae9
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
cec1ca8
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
6e4da2e
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
6afe2a1
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
42cb5e2
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
dfc195d
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
b9d38fb
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
d28c83b
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
6c7ab95
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
499fa9e
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
a6d401e
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
4488a7e
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
52891fe
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
986aec8
Datasets for creating web app
Yuuuuume7 Feb 1, 2024
d1258c7
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
7585268
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
94c73d3
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
7b2778c
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
53e2d5e
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
c8be362
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
1c6813a
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
fc11507
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
9334b07
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
585580f
Update requirements.txt
Yuuuuume7 Feb 1, 2024
767b5d4
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
43ef9f6
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
2e21fa1
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
1d0eee9
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
187e681
Update requirements.txt
Yuuuuume7 Feb 1, 2024
2aee140
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
c2728c5
Update requirements.txt
Yuuuuume7 Feb 1, 2024
7327580
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
7d64b63
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
0485337
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
82f87b5
Update streamlit_app.py
Yuuuuume7 Feb 1, 2024
55bb113
Update streamlit_app.py
Yuuuuume7 Feb 2, 2024
0beb83e
Add files via upload
Yuuuuume7 Feb 13, 2024
663c1c5
Delete over_sampled_df_fe.csv
Yuuuuume7 Feb 13, 2024
984b900
Delete requirements.txt
Yuuuuume7 Feb 13, 2024
06cdf70
Delete streamlit_app.py
Yuuuuume7 Feb 13, 2024
2eab49c
Delete test_sampled_df_fe.csv
Yuuuuume7 Feb 13, 2024
31b5cfe
Update config.toml
Yuuuuume7 Feb 13, 2024
cd1bf06
Add files via upload
Yuuuuume7 Feb 15, 2024
06f3608
Update README.md
Yuuuuume7 Feb 15, 2024
28d75d4
Add files via upload
Yuuuuume7 Feb 15, 2024
85d5615
Delete streamlit_app.py
Yuuuuume7 Feb 15, 2024
2e79146
Delete App directory
Yuuuuume7 Feb 16, 2024
8839245
Delete streamlit_app (1).py
Yuuuuume7 Feb 16, 2024
f97151b
Add files via upload
Yuuuuume7 Feb 16, 2024
a8c5a6c
Delete config.toml
Yuuuuume7 Feb 16, 2024
536292e
Add files via upload
Yuuuuume7 Feb 16, 2024
427a511
Create config.toml
Yuuuuume7 Feb 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[theme]
primaryColor="#666666"
backgroundColor="#EEFFFF"
secondaryBackgroundColor="#FFFFFF"
textColor="#262730"
font="sans serif"
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
# Welcome to Streamlit!

Edit `/streamlit_app.py` to customize this app to your heart's desire. :heart:

If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).
Binary file added cap_model.sav
Binary file not shown.
Binary file added cap_pca.sav
Binary file not shown.
Binary file added cap_proba.sav
Binary file not shown.
Binary file added cap_rfe.sav
Binary file not shown.
Binary file added cap_scaler.sav
Binary file not shown.
6 changes: 6 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[theme]
primaryColor="#666666"
backgroundColor="#EEFFFF"
secondaryBackgroundColor="#FFFFFF"
textColor="#262730"
font="sans serif"
408,521 changes: 408,521 additions & 0 deletions over_sampled_df_fe.csv

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
altair
pandas
streamlit
scikit-learn
prediction
colour

211 changes: 176 additions & 35 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,179 @@
import pandas as pd
import streamlit as st

"""
# Welcome to Streamlit!

Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
forums](https://discuss.streamlit.io).

In the meantime, below is an example of what you can do with just a few lines of code:
"""

num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)

indices = np.linspace(0, 1, num_points)
theta = 2 * np.pi * num_turns * indices
radius = indices

x = radius * np.cos(theta)
y = radius * np.sin(theta)

df = pd.DataFrame({
"x": x,
"y": y,
"idx": indices,
"rand": np.random.randn(num_points),
})

st.altair_chart(alt.Chart(df, height=700, width=700)
.mark_point(filled=True)
.encode(
x=alt.X("x", axis=None),
y=alt.Y("y", axis=None),
color=alt.Color("idx", legend=None, scale=alt.Scale()),
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
))

st.title("Welcome to Heart Disease Risk Prediction!!")

st.header("Fill out the Following Questions:")

st.write("Personal Detail Question")
username = st.text_input("Enter your name")
sex = st.radio("Select Gender:", ("Male", "Female"))
age = st.selectbox("Select Age Group:",
["18-24", "25-29", "30-34", "35-39", "40-44", "45-49", "50-54",
"55-59", "60-64", "65-69", "70-74", "75-79", "80 or older"],
placeholder="Select One")
race = st.selectbox("Select Race:", ["White", "Hispanic", "Black", "Asian", "American Indian/Alaskan Native"],
placeholder="Select One")
height = st.number_input("Enter your Height (in centimeters):", min_value=100.00, max_value=250.00,
value=150.00, step=5.00)
weight = st.number_input("Enter your Weight (in kilograms):", min_value=30.00, max_value=200.00,
value=50.00, step=5.00)


st.text(" ")
st.text(" ")
st.write("Daily Activity Question")
sleep = st.number_input("Enter Average Sleep Time:", min_value=0.0, max_value=24.0,
value=7.0, step=0.5)
activity = st.radio("During the past month, other than your regular job, did you participate in any physical activities or exercises such as running, calisthenics, golf, gardening, or walking for exercise?:",
("Yes", "No"), index=1)
smoking = st.radio("Have you smoked at least 100 cigarettes in your entire life?:",
("Yes", "No"), index=1)
drinking = st.radio("Do you drink a lot (adult men having more than 14 drinks per week or adult women having more than 7 drinks per week)?:",
("Yes", "No"), index=1)


st.text(" ")
st.text(" ")
st.write("Health Status")
genhealth = st.selectbox("Would you say that in general your health is:", ['Excellent', 'Very good', 'Good', 'Fair', 'Poor'],
index=2)
physicalhealth = st.selectbox("During the past month, how many days did you have physical health problem, which includes physical illness and injury?:", range(0, 31))
mentalhealth = st.selectbox("During the past month, how many days did you have mental health problem?:", range(0, 31))
diffwalking = st.radio("Do you have serious difficulty walking or climbing stairs?:",
("Yes", "No"), index=1)
asthma = st.radio("(Ever told) (you had) asthma?:", ("Yes", "No"), index=1)

st.text(" ")
st.text(" ")
button = st.button('Predict')

bmi = weight / ((height/100)**2)




# Creating a Machine Learning Model

from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
from sklearn.feature_selection import RFE
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier

over_sampled_df = pd.read_csv("./over_sampled_df_fe.csv")
test_sampled_df = pd.read_csv("./test_sampled_df_fe.csv")

X_train_over = over_sampled_df.drop(columns="HeartDisease")
y_train_over = over_sampled_df["HeartDisease"]

X_test_sampled = test_sampled_df.drop(columns="HeartDisease")
y_test_sampled = test_sampled_df["HeartDisease"]

scaler = StandardScaler()
scaler.fit(X_train_over)
X_scaled_train = scaler.transform(X_train_over)
X_scaled_test = scaler.transform(X_test_sampled)

rfe_over = RFE(estimator=LogisticRegression(max_iter=1000, random_state=42), n_features_to_select=11)
rfe_over.fit(X_scaled_train,y_train_over)
import joblib
joblib.dump(rfe_over, "cap_rfe.sav")

scaler = StandardScaler()
scaler.fit(X_train_over.loc[:, rfe_over.support_])
X_scaled_train = scaler.transform(X_train_over.loc[:, rfe_over.support_])
X_scaled_test = scaler.transform(X_test_sampled.loc[:, rfe_over.support_])
import joblib
joblib.dump(scaler, "cap_scaler.sav")

my_PCA = PCA()
my_PCA.fit(X_scaled_train)
X_train_PCA = my_PCA.transform(X_scaled_train)
X_test_PCA = my_PCA.transform(X_scaled_test)
import joblib
joblib.dump(my_PCA, "cap_pca.sav")

cap_model = LogisticRegression(max_iter=1000, C=0.0001, penalty="l2", solver="liblinear", random_state=42)
cap_model.fit(X_train_PCA,y_train_over)
import joblib
joblib.dump(cap_model, "cap_model.sav")


#from prediction import predict
def predict(df):
scaler = joblib.load("cap_scaler.sav")
rfe_over = joblib.load("cap_rfe.sav")
my_PCA = joblib.load("cap_pca.sav")
cap_model = joblib.load("cap_model.sav")

yes_no_columns = ["Smoking", "AlcoholDrinking", "DiffWalking", "PhysicalActivity", "Asthma"]

for column in yes_no_columns:
df[column] = df[column].map({"No":0, "Yes":1})

df["Sex"] = df["Sex"].replace({"Male":1, "Female":0})

df["AgeCategory"] = df["AgeCategory"].replace({'55-59':55, '80 or older':80, '65-69':65, '75-79':75,
'40-44':40, '70-74':70,'60-64':60, '50-54':50, '45-49':45,
'18-24':18, '35-39':35, '30-34':30, '25-29':25})

df["GenHealth"] = df["GenHealth"].replace({'Very good':3, 'Fair':1, 'Good':2, 'Poor':0, 'Excellent':4})


race_column = ["Race_American Indian/Alaskan Native", "Race_Asian", "Race_Black", "Race_Hispanic", "Race_Other", "Race_White"]
df[race_column] = 0
race_list = ["American Indian/Alaskan Native", "Asian", "Black", "Hispanic", "Other", "White"]
for index in range(len(race_list)):
if df.loc[0, "Race"] == race_list[index]:
df[race_column[index]] = 1
cap_df = df.drop(columns="Race")


scaled_df = scaler.transform(cap_df.loc[:, rfe_over.support_])

pca_df = my_PCA.transform(scaled_df)

cap_proba = cap_model.predict_proba(pca_df)
cap_pred = (cap_proba[:, 1] >= 0.52).astype(int)

#import joblib
joblib.dump(cap_proba, "cap_proba.sav")

if cap_pred == 1:
#result_high='<p style="color:Red; font-size: 25px;">HIGH</p>'
st.markdown(f"Based from the Machine Learning model,")
st.markdown(f"your risk of developing Heart Disease is:")
#st.markdown(result_high, unsafe_allow_html=True)

st.error('HIGH')


else:
st.balloons()
#result_low='<p style="color:Blue; font-size: 25px;">LOW</p>'
st.markdown(f"Based from the Machine Learning model, your risk of developing Heart Disease is:")
#st.markdown(result_low, unsafe_allow_html=True)

st.warning('LOW')


data = [bmi, smoking, drinking, physicalhealth, mentalhealth, diffwalking, sex, age, race, activity, genhealth, sleep, asthma]
user_df = pd.DataFrame(data, index = ["BMI", "Smoking", "AlcoholDrinking", "PhysicalHealth", "MentalHealth", "DiffWalking", "Sex", "AgeCategory", "Race", "PhysicalActivity", "GenHealth", "SleepTime", "Asthma"])
user_df = user_df.T


if button:
st.text(f"Hi {username}!")
predict(user_df)

st.text(" ")
st.text(" ")
cap_proba = joblib.load("cap_proba.sav")
st.markdown(f"According to the machine learning model:")
st.success(f"The Probability that it will classify you as at risk for heart disease are: {int(cap_proba[:, 1]*100)}%, the Probability that it will classify you as at no risk for heart disease are: {int(cap_proba[:, 0]*100)}%")
st.text(" ")
st.text(" ")
st.markdown(f"Note: If the Probability it will classify you at risk is over 52%, then the model will classify you as at risk for heart disease")
Loading