|
import streamlit as st
|
|
import pandas as pd
|
|
from predict import InsuranceClaimPredictor
|
|
|
|
|
|
predictor = InsuranceClaimPredictor('model/insurance_claim_prediction_model.joblib')
|
|
|
|
|
|
st.title('Insurance Claim Prediction')
|
|
|
|
|
|
st.sidebar.header('User Input Parameters')
|
|
|
|
def user_input_features():
|
|
age = st.sidebar.number_input('Age (in years)', min_value=0, max_value=100, value=40)
|
|
|
|
sex = st.sidebar.selectbox('Sex', ['male', 'female'])
|
|
|
|
bmi = st.sidebar.number_input('BMI (Body Mass Index)', min_value=0.0, max_value=50.0, value=25.3)
|
|
|
|
children = st.sidebar.number_input('Number of Children', min_value=0, max_value=10, value=2)
|
|
|
|
smoker = st.sidebar.selectbox('Smoker', ['yes', 'no'])
|
|
|
|
region = st.sidebar.selectbox('Region', ['northeast', 'northwest', 'southeast', 'southwest'])
|
|
|
|
charges = st.sidebar.number_input('Medical Charges ($)', min_value=0.0, max_value=100000.0, value=2900.0)
|
|
|
|
|
|
data = {'age': age,
|
|
'sex': sex,
|
|
'bmi': bmi,
|
|
'children': children,
|
|
'smoker': smoker,
|
|
'region': region,
|
|
'charges': charges}
|
|
features = pd.DataFrame(data, index=[0])
|
|
return features
|
|
|
|
df = user_input_features()
|
|
|
|
|
|
if st.sidebar.button('Predict'):
|
|
|
|
prediction = predictor.predict(df)
|
|
|
|
|
|
if prediction[0] == 1:
|
|
st.sidebar.success('This person is likely to make an insurance claim.')
|
|
else:
|
|
st.sidebar.info('This person is less likely to make an insurance claim.')
|
|
|
|
|
|
st.subheader('User Input Parameters')
|
|
|
|
|
|
st.write("""
|
|
- **Age**: The age of the individual.
|
|
- **Sex**: The gender of the individual.
|
|
- **BMI**: Body Mass Index, a measure of body fat based on height and weight.
|
|
- **Number of Children**: Number of children or dependents.
|
|
- **Smoker**: Whether the individual is a smoker.
|
|
- **Region**: The geographical region where the individual resides.
|
|
- **Medical Charges**: Annual medical charges billed.
|
|
""")
|
|
|
|
|
|
st.subheader('Demo Data')
|
|
|
|
|
|
demo_data = pd.DataFrame({
|
|
'age': [23, 45],
|
|
'sex': ['female', 'male'],
|
|
'bmi': [22.0, 30.0],
|
|
'children': [0, 2],
|
|
'smoker': ['no', 'yes'],
|
|
'region': ['southeast', 'northwest'],
|
|
'charges': [2000.0, 12000.0],
|
|
'claim': ['No', 'Yes']
|
|
})
|
|
|
|
st.write(demo_data)
|
|
|
|
|
|
st.subheader('Analysis Dashboard')
|
|
|
|
claimed_data = demo_data[demo_data['claim'] == 'Yes']
|
|
not_claimed_data = demo_data[demo_data['claim'] == 'No']
|
|
|
|
|
|
st.write(f"### Charges Analysis")
|
|
st.write(f"- **Average charges for claims made**: ${claimed_data['charges'].mean():.2f}")
|
|
st.write(f"- **Average charges for claims not made**: ${not_claimed_data['charges'].mean():.2f}")
|
|
|