-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstreamlit_app.py
93 lines (67 loc) · 2.99 KB
/
streamlit_app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import numpy as np
import pickle
import streamlit as st
import pandas as pd
from sklearn.preprocessing import StandardScaler
from sklearn.preprocessing import LabelEncoder
scaler=StandardScaler()
encoder= LabelEncoder()
# loading the saved model
loaded_model = pickle.load(open('trained_model.sav', 'rb'))
# creating a function for Prediction
def diabetes_prediction(input_data):
# Convert categorical data to numerical values
map_name = {'Male': 1, 'Female': 2, 'Others': 3}
gender = input_data[0]
input_data[0] = map_name[gender]
# Fit encoder on the original dataset values for 'Smoking history'
sample_smoking_history = ['No Info', 'Current', 'Ever', 'Former', 'Never', 'Not Current'] # Provide your dataset values
encoder.fit(sample_smoking_history)
input_data[7] = encoder.transform([input_data[7]])[0]
# Create a DataFrame for the input data
df = pd.DataFrame([input_data])
# Load the dataset for scaling
dataset_for_scaling = pd.read_csv('output.csv') # Replace with your actual dataset path
# Fit the scaler on the dataset for scaling
scaler.fit(dataset_for_scaling)
# Transform the input data using the fitted scaler
X = scaler.transform(df)
prediction = loaded_model.predict(X)
if prediction[0] == 0:
return 'The person is not diabetic'
else :
return 'The person is diabetic'
def main():
# giving a title
st.title('Diabetes Prediction Web App')
# getting the input data from the user
gender= st.selectbox(
'Please select your Gender',
('Male', 'Female', 'Others'))
st.write('You selected:', gender)
age = st.number_input('Enter your Age',value=0, min_value=0,step=1, max_value=100)
hypertension = st.checkbox('suffering from Hypertension or not?')
if hypertension:
st.write(1)
else:
st.write(0)
heart_disease = st.checkbox('suffering from Heart Disease or not?')
if heart_disease:
st.write(1)
else:
st.write(0)
bmi = st.number_input('Enter your BMI Index',value=0.00,step=0.01,format="%.2f", min_value=0.00)
HbA1c_level = st.number_input('Enter your HbA1c_level level',value=0.0,step=0.1,format="%.1f", min_value=0.0)
blood_glucose_level = st.number_input('Enter your blood glucose level',value=0.0,step=0.1,format="%.1f", min_value=0.0)
smoking_history = st.selectbox(
"Please select your Smoking history",
("No Info", "Current", "Ever", "Former", "Never", "Not Current"))
st.write('You selected:', smoking_history)
# code for Prediction
diagnosis = ''
# creating a button for Prediction
if st.button('Diabetes Test Result'):
diagnosis = diabetes_prediction([gender,age,hypertension,heart_disease,bmi,HbA1c_level,blood_glucose_level,smoking_history])
st.success(diagnosis)
if __name__ == '__main__':
main()