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.write(""" # Heart Disease Detection App """) url_dataset = f'Download Dataset CSV File' st.markdown(url_dataset, unsafe_allow_html=True) def user_input_features() : age = st.sidebar.slider('age', 29.0, 77.0) sex = st.sidebar.slider('sex', 0.0, 1.0) cp = st.sidebar.slider('cp', 0.0, 3.1) trestbps = st.sidebar.slider('trestbps', 94.0, 200.0) chol = st.sidebar.slider('chol', 126.0, 564.0) fbs = st.sidebar.slider('fbs', 0.0, 1.0) restecg = st.sidebar.slider('restec', 0.0, 2.0) thalach = st.sidebar.slider('thalach', 71.0, 202.0) exang = st.sidebar.slider('exang', 0.0, 1.0) oldpeak = st.sidebar.slider('oldpeak', 0.0, 6.2) slope = st.sidebar.slider('slope', 0.0, 2.0) ca = st.sidebar.slider('ca', 0.0, 4.0) thal = st.sidebar.slider ('thal', 0.0, 3.0) data = {'age':[age], 'sex':[sex], 'cp':[cp], 'trestbps': [trestbps], 'chol': [chol], 'fbs': [fbs], 'restecg': [restecg], 'thalach':[thalach], 'exang':[exang], 'oldpeak': [oldpeak], 'slope':[slope], 'ca':[ca], 'thal':[thal]} features = pd.DataFrame(data) return features input_df = user_input_features() heart_raw = pd.read_csv('heart.csv') heart_raw.fillna(0, inplace=True) heart = heart_raw.drop(columns=['target']) df = pd.concat([input_df, heart],axis=0) df = df[:1] # Selects only the first row (the user input data) df.fillna(0, inplace=True) features = ['age', 'sex', 'cp', 'trestbps', 'chol', 'fbs', 'restecg', 'thalach', 'exang', 'oldpeak', 'slope', 'ca', 'thal'] df = df[features] st.subheader('User Input features') st.write(df) load_clf = pickle.load(open('heart.pkl', 'rb')) detection = load_clf.predict(df) detection_proba = load_clf.predict_proba(df) heart_labels = np.array(['Normal', 'Cardiovacular']) st.subheader('Detection') #st.write(detection) st.write(heart_labels[int(detection)]) st.subheader('Detection Probability') st.write(detection_proba) #df_prob = pd.DataFrame(data=detection_proba, index=['Probability'], columns=credit_labels) #st.write(df_prob)