Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine Learning Model Implemented #139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6,358 changes: 6,358 additions & 0 deletions Stroke Prediction/Project.ipynb

Large diffs are not rendered by default.

138 changes: 138 additions & 0 deletions Stroke Prediction/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import streamlit as st
import joblib
import os
import random

# Directory to load the models
model_dir = "saved_models"

# Load the models
lrClassifier = joblib.load(os.path.join(model_dir, 'logistic_regression_model.pkl'))
nbClassifier = joblib.load(os.path.join(model_dir, 'naive_bayes_model.pkl'))

# Function to make predictions
def make_prediction(features):
predictions = {
"Logistic Regression": lrClassifier.predict([features])[0],
"Naive Bayes": nbClassifier.predict([features])[0],
}
return predictions

# List of healthy life quotes
healthy_life_quotes = [
"Eat a balanced diet.",
"Exercise regularly.",
"Get enough sleep.",
"Stay hydrated.",
"Practice mindfulness.",
"Avoid smoking.",
"Limit alcohol intake.",
"Maintain a healthy weight.",
"Stay socially connected.",
"Get regular medical check-ups."
]

# Initialize session state for theme
if 'theme' not in st.session_state:
st.session_state['theme'] = 'light'

# Function to toggle theme
def toggle_theme():
if st.session_state['theme'] == 'light':
st.session_state['theme'] = 'dark'
else:
st.session_state['theme'] = 'light'

# Apply CSS based on the theme
if st.session_state['theme'] == 'light':
page_bg_img = '''
<style>
.stApp {
background: rgba(255, 255, 255, 0.8);
color: #000000;
padding: 20px;
border-radius: 10px;
}
.stButton>button {
background-color: #4CAF50;
color: white;
border-radius: 12px;
padding: 10px 24px;
border: none;
}
.stButton>button:hover {
background-color: #45a049;
}
</style>
'''
else:
page_bg_img = '''
<style>
.stApp {
background: rgba(0, 0, 0, 0.7);
color: #ffffff;
padding: 20px;
border-radius: 10px;
}
.stButton>button {
background-color: #4CAF50;
color: white;
border-radius: 12px;
padding: 10px 24px;
border: none;
}
.stButton>button:hover {
background-color: #45a049;
}
</style>
'''

st.markdown(page_bg_img, unsafe_allow_html=True)

# Sidebar inputs
st.sidebar.title('Prediction Details')

gender = st.sidebar.selectbox('Gender', ('Male', 'Female'))
age = st.sidebar.slider('Age', 0, 100)
glucose_level = st.sidebar.slider('Glucose Level', 0, 300)
bmi = st.sidebar.slider('BMI (Body Mass Index)', 18, 30)
hypertension = st.sidebar.radio('Hypertension', ("Yes", "No"))
heart_disease = st.sidebar.radio('Heart Disease', ("Yes", "No"))
work_type = st.sidebar.radio('Work Type', ('Private', 'Self Employed', 'Government job', 'Children', 'Never Worked'))

# Map inputs to features
gender_map = {'Male': 0, 'Female': 1}
hypertension_map = {'Yes': 1, 'No': 0}
heart_disease_map = {'Yes': 1, 'No': 0}
work_type_map = {'Private': 0, 'Self Employed': 1, 'Government job': 2, 'Children': 3, 'Never Worked': 4}

features = [
gender_map[gender],
age,
hypertension_map[hypertension],
heart_disease_map[heart_disease],
work_type_map[work_type],
glucose_level,
bmi
]

# Main page title and header
st.title("Brain Stroke Prediction Tool")
st.header("Input Parameters")

# Theme toggle button
if st.sidebar.button('Toggle Theme'):
toggle_theme()

# Predict button
if st.button('Predict'):
predictions = make_prediction(features)
st.subheader("Predictions")
for model, prediction in predictions.items():
st.write(f"{model}: {'Stroke' if prediction == 1 else 'No Stroke'}")

# Button for healthy life quotes
if st.button('Get Healthy Life Quote'):
quote = random.choice(healthy_life_quotes)
st.subheader("Healthy Life Quote")
st.write(quote)
Binary file not shown.
Binary file not shown.
Binary file added Stroke Prediction/saved_models/gbm_model.pkl
Binary file not shown.
Binary file added Stroke Prediction/saved_models/knn_model.pkl
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions Stroke Prediction/saved_models/neural_network_model.pkl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
�
Binary file not shown.
Binary file added Stroke Prediction/saved_models/svm_model.pkl
Binary file not shown.
Binary file added Stroke Prediction/saved_models/xgb_model.pkl
Binary file not shown.