File size: 2,998 Bytes
60434a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import streamlit as st
import pandas as pd
from predict import InsuranceClaimPredictor

# Initialize the predictor
predictor = InsuranceClaimPredictor('model/insurance_claim_prediction_model.joblib')

# Title of the Streamlit app
st.title('Insurance Claim Prediction')

# Sidebar for user input
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()

# Button for prediction
if st.sidebar.button('Predict'):
    # Make prediction
    prediction = predictor.predict(df)
    
    # Display the prediction
    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.')

# Display user input
st.subheader('User Input Parameters')

# Add descriptions for each input
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.

""")

# Demo data
st.subheader('Demo Data')

# Sample data for demo
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)

# Notifications for analysis
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}")