Upload 4 files
Browse files- log_reg.pkl +3 -0
- requirements.txt +5 -0
- transformer.pkl +3 -0
- walaa.py +93 -0
log_reg.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4b2507397ff144aa00ea8d45ec4ab7ee63aed6f184441aed6a39f0165a08b189
|
3 |
+
size 167767
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
scikit-learn
|
3 |
+
streamlit
|
4 |
+
numpy
|
5 |
+
xgboost
|
transformer.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0aff2c332904392ca09ad644aa923c37f853134a653e04b478a1646028539671
|
3 |
+
size 1669
|
walaa.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pickle as pkl
|
3 |
+
import base64
|
4 |
+
import pandas as pd
|
5 |
+
import sklearn
|
6 |
+
|
7 |
+
|
8 |
+
st.image ('https://www.chathamsafetynet.org/wp-content/uploads/2021/08/Copy-of-Copy-of-PST-Logo-background-e1628697628477.png')
|
9 |
+
|
10 |
+
# front end elements of the web page
|
11 |
+
html_temp = """
|
12 |
+
<div style ="background-color:skyblue;padding:13px">
|
13 |
+
<h1 style ="color:black;text-align:center;">Suicide Prediction App</h1>
|
14 |
+
</div>
|
15 |
+
"""
|
16 |
+
# display the front end aspect
|
17 |
+
st.markdown(html_temp, unsafe_allow_html = True)
|
18 |
+
st.subheader('by Dr.Walaa Nasr')
|
19 |
+
|
20 |
+
st.write('The goal of this project is to gather data about people that might think of suicide attempts, to predict the suicide rates using Machine Learning algorithms and analyzing them to find correlated factors causing increase in suicide rates globally')
|
21 |
+
|
22 |
+
st.title('if you can predict it, you can prevent it')
|
23 |
+
|
24 |
+
#take input from user
|
25 |
+
|
26 |
+
Age=st.selectbox ("Age",range(18,121,1))
|
27 |
+
|
28 |
+
Sex = st.radio("Select Gender: ", range (1,3,1))
|
29 |
+
st.info ('male=1, female=2')
|
30 |
+
|
31 |
+
Race = st.radio("Select Race: ", range (1,7,1))
|
32 |
+
st.info ('White=1, African_American =2, Hispanic=3, Asian=4, Native_American=5, Other=6')
|
33 |
+
|
34 |
+
Education = st.slider("Select education: ", 1, 6,20)
|
35 |
+
|
36 |
+
score = st.selectbox(" score of ADHD & MD: ", range(0,200,1))
|
37 |
+
|
38 |
+
subs = st.selectbox(" substance abuse: ", range(0,200,1))
|
39 |
+
|
40 |
+
legal = st.selectbox(" Legal issues: ", range(0,20,1))
|
41 |
+
|
42 |
+
Abuse = st.selectbox(" Abuse history: ",range (0,8,1))
|
43 |
+
|
44 |
+
|
45 |
+
ABUSE = st.info ("No=0, physical=1, Sexual=2, Emotional=3, Physical & Sexual=4, Physical & Emotional=5, Sexual & Emotional=6, Physical & Sexual & Emotional=7")
|
46 |
+
|
47 |
+
Non_subst_Dx= st.selectbox("non_substance_diagnosis:",range(0,3,1))
|
48 |
+
|
49 |
+
st.info('none=0,one=1,more_than_one=2')
|
50 |
+
|
51 |
+
Subst_Dx = st.selectbox("substance diagnosis:", range(0,4,1))
|
52 |
+
|
53 |
+
st.info('none=0,one_Substance_related=1, two_substance_related=2, three_or_more_substance_related=3')
|
54 |
+
|
55 |
+
st.sidebar.subheader("About App")
|
56 |
+
|
57 |
+
st.sidebar.info("This web app is helps doctors to find out whether patients are at a risk of commiting suicidal attempts or not")
|
58 |
+
st.sidebar.info("Enter the required fields and click on the 'Predict' button to check whether your patient has risk for suicidal attempt")
|
59 |
+
st.sidebar.info("Don't forget to rate this app")
|
60 |
+
|
61 |
+
feedback = st.sidebar.slider('How much would you rate this app?',min_value=0,max_value=5,step=1)
|
62 |
+
|
63 |
+
if feedback:
|
64 |
+
st.header("Thank you for rating the app!")
|
65 |
+
st.info("Caution: This is just a prediction and can't gaurantee that your patient will not try to suicide.")
|
66 |
+
|
67 |
+
|
68 |
+
# convert inputs to DataFrame
|
69 |
+
|
70 |
+
df_new = pd.DataFrame ({'Age': [Age], 'Sex':[Sex], "Race": [Race], 'Education': [Education], 'score':[score], 'subs':[subs], 'legal': [legal], 'Abuse': [Abuse], 'Subst_Dx': [Subst_Dx],'Non_subst_Dx':[Non_subst_Dx] })
|
71 |
+
|
72 |
+
# load transformer
|
73 |
+
transformer = pkl.load(open('transformer.pkl','rb'))
|
74 |
+
#apply transformer on inputs
|
75 |
+
x_new = transformer.transform (df_new)
|
76 |
+
|
77 |
+
# load model
|
78 |
+
loaded_model = pkl.load(open('log_reg.pkl' ,'rb'))
|
79 |
+
|
80 |
+
|
81 |
+
#predict the output
|
82 |
+
predictx= loaded_model.predict(x_new)[0]
|
83 |
+
|
84 |
+
#file_ = open("kramer_gif.gif", "rb")
|
85 |
+
#contents = loaded_model.read()
|
86 |
+
#data_url = base64.b64encode(contents).decode("utf-8")
|
87 |
+
#loaded_model.close()
|
88 |
+
|
89 |
+
if st.button("Predict"):
|
90 |
+
if(predictx==1):
|
91 |
+
st.error("Warning! this patient has chances of attempting suicide")
|
92 |
+
else:
|
93 |
+
st.success("this patient is healthy and is less likely to attempt suicide!")
|