diqitalize commited on
Commit
598e853
1 Parent(s): 6d4a4ad

Fetal health 1

Browse files
Files changed (6) hide show
  1. Procfile +1 -0
  2. app.py +107 -0
  3. fetal_clf.pkl +3 -0
  4. fetal_health.csv +0 -0
  5. requirements.txt +6 -0
  6. setup.sh +13 -0
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: sh setup.sh && streamlit run app.py
app.py ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pandas as pd
3
+ import numpy as np
4
+ import pickle
5
+ import base64
6
+ import seaborn as sns
7
+ import matplotlib.pyplot as plt
8
+
9
+ st.set_page_config(
10
+ page_title="Fetal Health App"
11
+ )
12
+
13
+
14
+ st.title('Fetal Health Classification')
15
+ st.write("""
16
+
17
+ ## Context
18
+
19
+ Reduction of child mortality is reflected in several of the United Nations' Sustainable Development Goals and is a key indicator of human progress.
20
+ The UN expects that by 2030, countries end preventable deaths of newborns and children under 5 years of age, with all countries aiming to reduce under‑5 mortality to at least as low as 25 per 1,000 live births.
21
+
22
+ Parallel to notion of child mortality is of course maternal mortality, which accounts for 295 000 deaths during and following pregnancy and childbirth (as of 2017). The vast majority of these deaths (94%) occurred in low-resource settings, and most could have been prevented.
23
+
24
+ In light of what was mentioned above, Cardiotocograms (CTGs) are a simple and cost accessible option to assess fetal health, allowing healthcare professionals to take action in order to prevent child and maternal mortality. The equipment itself works by sending ultrasound pulses and reading its response, thus shedding light on fetal heart rate (FHR), fetal movements, uterine contractions and more.
25
+
26
+ ## Data
27
+
28
+ This dataset contains 2126 records of features extracted from Cardiotocogram exams, which were then classified by three expert obstetritians into 3 classes:
29
+
30
+ * Normal
31
+ * Suspect
32
+ * Pathological
33
+
34
+ """)
35
+
36
+ url_dataset = f'<a href="fetal_health.csv">Download Dataset CSV File</a>'
37
+ st.markdown(url_dataset, unsafe_allow_html=True)
38
+
39
+ def user_input_features() :
40
+ baseline_value = st.sidebar.slider('Baseline Value', 106.0, 160.0)
41
+ accelerations = st.sidebar.slider('Accelerations', 0.0, 0.019)
42
+ fetal_movement = st.sidebar.slider('Fetal Movement', 0.0, 0.481)
43
+ uterine_contractions = st.sidebar.slider('Uterine Contractions', 0.0, 0.015)
44
+ light_decelerations = st.sidebar.slider('Light Decelerations', 0.0, 0.015)
45
+ severe_decelerations = st.sidebar.slider('Severe Decelerations', 0.0, 0.001)
46
+
47
+
48
+ data = {'baseline value':[baseline_value],
49
+ 'accelerations':[accelerations],
50
+ 'fetal_movement':[fetal_movement],
51
+ 'uterine_contractions':[uterine_contractions],
52
+ 'light_decelerations':[light_decelerations],
53
+ 'severe_decelerations':[severe_decelerations]
54
+ }
55
+
56
+ features = pd.DataFrame(data)
57
+ return features
58
+
59
+ input_df = user_input_features()
60
+
61
+
62
+ fetal_raw = pd.read_csv('fetal_health.csv')
63
+ fetal_raw.fillna(0, inplace=True)
64
+ fetal = fetal_raw.drop(columns=['fetal_health'])
65
+ df = pd.concat([input_df, fetal], axis=0)
66
+
67
+ df = df[:1] # Selects only the first row (the user input data)
68
+ df.fillna(0, inplace=True)
69
+
70
+ features = ['baseline value', 'accelerations', 'fetal_movement',
71
+ 'uterine_contractions',
72
+ 'light_decelerations',
73
+ 'severe_decelerations',
74
+ 'prolongued_decelerations',
75
+ 'abnormal_short_term_variability',
76
+ 'mean_value_of_short_term_variability',
77
+ 'percentage_of_time_with_abnormal_long_term_variability',
78
+ 'mean_value_of_long_term_variability',
79
+ 'histogram_width',
80
+ 'histogram_min',
81
+ 'histogram_max',
82
+ 'histogram_number_of_peaks',
83
+ 'histogram_number_of_zeroes',
84
+ 'histogram_mode',
85
+ 'histogram_mean',
86
+ 'histogram_median',
87
+ 'histogram_variance',
88
+ 'histogram_tendency'
89
+ ]
90
+
91
+ df = df[features]
92
+
93
+
94
+ st.subheader('User Input features')
95
+ st.write(df)
96
+
97
+ load_clf = pickle.load(open('fetal_clf.pkl', 'rb'))
98
+ prediction = load_clf.predict(df)
99
+ prediction_proba = load_clf.predict_proba(df)
100
+ fetal_labels = np.array(['Normal', 'Suspect', 'Pathological'])
101
+ st.subheader('Prediction')
102
+ st.write(fetal_labels[int(prediction)-1])
103
+ st.subheader('Prediction Probability')
104
+ df_prob = pd.DataFrame(data = prediction_proba,
105
+ index = ['Probability'],
106
+ columns = fetal_labels)
107
+ st.write(df_prob)
fetal_clf.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8eab80ec12b941386e2e37acb4dcb31afcf45c377da56349b18128b9afe9bdbd
3
+ size 2256921
fetal_health.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ matplotlib==3.5.2
2
+ numpy==1.23.1
3
+ pandas==1.4.3
4
+ seaborn==0.11.2
5
+ streamlit==1.12.0
6
+ sklearn
setup.sh ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ mkdir -p ~/.streamlit/
2
+
3
+ echo "\
4
+ [general]\n\
5
+ email = \"your-email@domain.com\"\n\
6
+ " > ~/.streamlit/credentials.toml
7
+
8
+ echo "\
9
+ [server]\n\
10
+ headless = true\n\
11
+ enableCORS=false\n\
12
+ port = $PORT\n\
13
+ " > ~/.streamlit/config.toml