import streamlit as st import pandas as pd import joblib model = joblib.load("src/insurance_rf_model.pkl") feature_columns = joblib.load("src/feature_columns.pkl") st.title("Medical Insurance Cost Prediction") st.write("This app predicts medical insurance cost using a trained Random Forest model.") age = st.number_input("Age", min_value=18, max_value=100, value=30) sex = st.selectbox("Sex", ["female", "male"]) bmi = st.number_input("BMI", min_value=10.0, max_value=60.0, value=25.0) children = st.number_input("Children", min_value=0, max_value=10, value=0) smoker = st.selectbox("Smoker", ["no", "yes"]) region = st.selectbox( "Region", ["southwest", "southeast", "northwest", "northeast"] ) if st.button("Predict"): data = pd.DataFrame({ "age": [age], "sex": [1 if sex == "male" else 0], "bmi": [bmi], "children": [children], "smoker": [1 if smoker == "yes" else 0], "high_bmi": [1 if bmi > 30 else 0], "has_children": [1 if children > 0 else 0], "region_northwest": [1 if region == "northwest" else 0], "region_southeast": [1 if region == "southeast" else 0], "region_southwest": [1 if region == "southwest" else 0] }) data = data.reindex(columns=feature_columns, fill_value=0) prediction = model.predict(data)[0] st.success(f"Estimated Insurance Cost: ${prediction:,.2f}")