Obesity_Risk / app.py
elifsara's picture
Upload 4 files
e383a1d verified
import streamlit as st
import pickle
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
# Veri ön işleme nesnesini dosyadan yükleme
with open('preprocessor.pkl', 'rb') as f:
preprocessor = pickle.load(f)
# Modeli dosyadan yükleme
with open('obesity.pkl', 'rb') as f:
model = pickle.load(f)
# Uygulama başlığı ve açıklama
st.title("Obesity Risk Classifier")
st.write("Calculate your obesity risk here! Because who doesn't want to procrastinate starting a diet?")
# Kullanıcıdan veriler almak için input alanları
st.header("Please fill in the following information:")
# Numeric sütunlar
Age = st.number_input("Age", min_value=0, max_value=100, value=25, step=1)
Height = st.number_input("Height (cm)", min_value=100, max_value=250, value=170, step=1)
Weight = st.number_input("Weight (kg)", min_value=30, max_value=200, value=70, step=1)
FCVC = st.number_input("Frequency of consumption of vegetables", min_value=0.0, max_value=3.0, value=1.0, step=0.5)
NCP = st.number_input("Number of main meals", min_value=0, max_value=6, value=3, step=1)
CH2O = st.number_input("Daily water consumption", min_value=0.0, max_value=3.0, value=1.0, step=0.5)
FAF = st.number_input("Physical activity frequency", min_value=0.0, max_value=3.0, value=1.0, step=0.5)
TUE = st.number_input("Time spent sitting (hours)", min_value=0.0, max_value=16.0, value=8.0, step=1.0)
# Categoric sütunlar
Gender = st.selectbox("Gender", ("Female","Male"))
family_history_with_overweight = st.selectbox("Family history with overweight", ("yes", "no"))
FAVC = st.selectbox("Frequent consumption of high caloric food", ("yes", "no"))
CAEC = st.selectbox("Regular consumption of vegetables", ("Sometimes", "Frequently","Always","no"))
SMOKE = st.selectbox("Do you smoke?", ("no", "yes"))
SCC = st.selectbox("Time spent sitting (hours)", ("yes", "no"))
CALC = st.selectbox("Alcohol consumption", ("Sometimes", "no", "Frequently"))
MTRANS = st.selectbox("Transportation used", ("Automobile", "Walking ", "Motorbike", "Bike"))
# Verileri işleme ve model ile tahmin yapma
if st.button("Calculate Obesity Risk"):
# Kullanıcı verilerini modele uygun formata getirme
# Kategorik verileri encode etme
input_data = np.array([Gender, Age, Height, Weight, family_history_with_overweight, FAVC, FCVC, NCP, CAEC, SMOKE, CH2O, SCC, FAF, TUE, CALC, MTRANS]).reshape(1, -1)
input_data=pd.DataFrame()
print(input_data)
# Veri ön işleme adımlarını uygulama
input_data_processed = preprocessor.fit_transform(input_data)
# Risk tahmini
risk_prediction = model.predict(input_data_processed)
risk_category = "Low" if risk_prediction == 0 else "High"
# Tahmin sonucunu gösterme
st.subheader("Prediction Result:")
st.write(f"Your obesity risk is: {risk_category}. Let's see, diet or exercise, or maybe pizza? Your call!")
# İronik açıklamalar
if risk_category == "Low":
st.write("You're in luck! Your obesity risk is low. But still, keep eating healthy and stay active. After all, laziness adds weight!")
else:
st.write("Oh no, looks like your obesity risk is high. Time to give up pizzas and say hello to vegetables. Remember, diets always start on Mondays!")