File size: 3,636 Bytes
739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b e34216c 739086d 9e8a94b 739086d 9e8a94b 739086d 9e8a94b 739086d f0b42e7 4a8e8a0 |
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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# -*- coding: utf-8 -*-
"""
Diabetes Prediction Web App
"""
import numpy as np
import pickle
import streamlit as st
# Dictionary to hold different model names and their corresponding file paths
models = {
"Logistic Regression": "LogisticRegression_model.pkl",
"Decision Tree Classifier": "DecisionTreeClassifier_model.pkl",
"Random Forest Classifier": "RandomForestClassifier_model.pkl",
"SVC": "SVC_model.pkl"
}
# Load the default model (Logistic Regression in this case)
selected_model = "Logistic Regression"
loaded_model = pickle.load(open(models[selected_model], 'rb'))
# Function for making predictions
def diabetes_prediction(input_data, model):
# Load the selected model
loaded_model = pickle.load(open(models[model], 'rb'))
# Convert input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
input_data_reshaped = input_data_as_numpy_array.reshape(1, -1)
prediction = loaded_model.predict(input_data_reshaped)
if prediction[0] == 0:
return 'The person is not diabetic'
else:
return 'The person is diabetic'
# Main function for the Streamlit app
def main():
st.title('Diabetes Prediction Web App')
# Dropdown for model selection
selected_model = st.selectbox("Choose Prediction Method (Default: Logistic Regression)", list(models.keys()))
# Input fields for user data
Pregnancies = st.text_input('Number of Pregnancies')
Glucose = st.text_input('Glucose Level')
BloodPressure = st.text_input('Blood Pressure Value')
SkinThickness = st.text_input('Skin Thickness Value')
Insulin = st.text_input('Insulin Level')
BMI = st.text_input('BMI Value')
DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function Value')
Age = st.text_input('Age of the Person')
diagnosis = ''
# Prediction button
if st.button('Diabetes Test Result'):
try:
input_data = [
float(Pregnancies),
float(Glucose),
float(BloodPressure),
float(SkinThickness),
float(Insulin),
float(BMI),
float(DiabetesPedigreeFunction),
float(Age)
]
diagnosis = diabetes_prediction(input_data, selected_model)
except ValueError as e:
diagnosis = "Invalid input. Please enter numeric values for all fields."
st.success(diagnosis)
# Dummy Entries or Demo for showcasing
st.markdown('## Demo - Test with Dummy Entries')
# You can set default values for the inputs to showcase the prediction functionality
default_values = {
"Number of Pregnancies": 5,
"Glucose Level": 130,
"Blood Pressure Value": 80,
"Skin Thickness Value": 30,
"Insulin Level": 100,
"BMI Value": 35,
"Diabetes Pedigree Function Value": 0.5,
"Age of the Person": 40
}
demo_button = st.button('Run Demo')
if demo_button:
demo_input_data = [
default_values["Number of Pregnancies"],
default_values["Glucose Level"],
default_values["Blood Pressure Value"],
default_values["Skin Thickness Value"],
default_values["Insulin Level"],
default_values["BMI Value"],
default_values["Diabetes Pedigree Function Value"],
default_values["Age of the Person"]
]
demo_diagnosis = diabetes_prediction(demo_input_data, selected_model)
st.success(f'Demo Result: {demo_diagnosis}')
if __name__ == '__main__':
main()
|