Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import joblib | |
| import numpy as np | |
| # Load the saved model and scaler | |
| model = joblib.load("medical_model.pkl") | |
| scaler = joblib.load("scaler.pkl") | |
| st.title("Medical Insurance Cost Predictor") | |
| st.write("Enter your details to estimate insurance charges.") | |
| # User Inputs | |
| age = st.number_input("Age", min_value=18, max_value=100, value=25) | |
| bmi = st.number_input("BMI", min_value=10.0, max_value=60.0, value=22.0) | |
| children = st.slider("Number of Children", 0, 5, 0) | |
| smoker = st.selectbox("Do you smoke?", ["Yes", "No"]) | |
| sex = st.selectbox("Gender", ["Male", "Female"]) | |
| # Map inputs to match the model's training format | |
| smoker_val = 1 if smoker == "Yes" else 0 | |
| sex_val = 1 if sex == "Male" else 0 | |
| # (Note: For simplicity, we assume region 'Southwest' as default here) | |
| # For full accuracy, you'd add region radio buttons matching your get_dummies columns. | |
| features = np.array([[age, sex_val, bmi, children, smoker_val, 0, 0, 0]]) | |
| features_scaled = scaler.transform(features) | |
| if st.button("Predict Charges"): | |
| prediction = model.predict(features_scaled) | |
| st.success(f"Estimated Insurance Cost: ${prediction[0]:,.2f}") |