Fetal_Health / app.py
diqitalize's picture
Fetal health 1
598e853
import streamlit as st
import pandas as pd
import numpy as np
import pickle
import base64
import seaborn as sns
import matplotlib.pyplot as plt
st.set_page_config(
page_title="Fetal Health App"
)
st.title('Fetal Health Classification')
st.write("""
## Context
Reduction of child mortality is reflected in several of the United Nations' Sustainable Development Goals and is a key indicator of human progress.
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.
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.
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.
## Data
This dataset contains 2126 records of features extracted from Cardiotocogram exams, which were then classified by three expert obstetritians into 3 classes:
* Normal
* Suspect
* Pathological
""")
url_dataset = f'<a href="fetal_health.csv">Download Dataset CSV File</a>'
st.markdown(url_dataset, unsafe_allow_html=True)
def user_input_features() :
baseline_value = st.sidebar.slider('Baseline Value', 106.0, 160.0)
accelerations = st.sidebar.slider('Accelerations', 0.0, 0.019)
fetal_movement = st.sidebar.slider('Fetal Movement', 0.0, 0.481)
uterine_contractions = st.sidebar.slider('Uterine Contractions', 0.0, 0.015)
light_decelerations = st.sidebar.slider('Light Decelerations', 0.0, 0.015)
severe_decelerations = st.sidebar.slider('Severe Decelerations', 0.0, 0.001)
data = {'baseline value':[baseline_value],
'accelerations':[accelerations],
'fetal_movement':[fetal_movement],
'uterine_contractions':[uterine_contractions],
'light_decelerations':[light_decelerations],
'severe_decelerations':[severe_decelerations]
}
features = pd.DataFrame(data)
return features
input_df = user_input_features()
fetal_raw = pd.read_csv('fetal_health.csv')
fetal_raw.fillna(0, inplace=True)
fetal = fetal_raw.drop(columns=['fetal_health'])
df = pd.concat([input_df, fetal], axis=0)
df = df[:1] # Selects only the first row (the user input data)
df.fillna(0, inplace=True)
features = ['baseline value', 'accelerations', 'fetal_movement',
'uterine_contractions',
'light_decelerations',
'severe_decelerations',
'prolongued_decelerations',
'abnormal_short_term_variability',
'mean_value_of_short_term_variability',
'percentage_of_time_with_abnormal_long_term_variability',
'mean_value_of_long_term_variability',
'histogram_width',
'histogram_min',
'histogram_max',
'histogram_number_of_peaks',
'histogram_number_of_zeroes',
'histogram_mode',
'histogram_mean',
'histogram_median',
'histogram_variance',
'histogram_tendency'
]
df = df[features]
st.subheader('User Input features')
st.write(df)
load_clf = pickle.load(open('fetal_clf.pkl', 'rb'))
prediction = load_clf.predict(df)
prediction_proba = load_clf.predict_proba(df)
fetal_labels = np.array(['Normal', 'Suspect', 'Pathological'])
st.subheader('Prediction')
st.write(fetal_labels[int(prediction)-1])
st.subheader('Prediction Probability')
df_prob = pd.DataFrame(data = prediction_proba,
index = ['Probability'],
columns = fetal_labels)
st.write(df_prob)