File size: 24,853 Bytes
a485c7a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
import streamlit as st
import pandas as pd 
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import altair as alt
import plotly.express as px
from sklearn.model_selection import train_test_split
import joblib
import shap as shap
from xgboost import XGBClassifier
from sklearn.preprocessing import OneHotEncoder
from streamlit_shap import st_shap

# Cache the data 
@st.cache
def load_data():
    data = pd.read_csv('data_cleaned_new.csv')
    return data

@st.cache_resource
def load_model_and_encoder():
    xgb_model = joblib.load('xgb_model.joblib')
    ohe = joblib.load('ohe.joblib')
    return xgb_model, ohe

xgb_model, ohe = load_model_and_encoder()


# Load the data
data = load_data()

# Sidebars
st.sidebar.title("Explore Financial Insights")
option = st.sidebar.radio(
    "Select an analysis section:",
    ("Home", 'Description of Variables', "Regional-Based Analysis", "Income-Based Analysis", "Gender-Based Analysis", "Financial Recommender Engine", "SML Classification")
)            

# Add a summary of Findex at the bottom of the sidebar
st.sidebar.markdown("### What is Findex?")
st.sidebar.write("""
The Global Findex database provides comprehensive data on how adults worldwide save, borrow, make payments, and manage risk. 
Launched with support from the Bill & Melinda Gates Foundation, the database is updated every three years and is the world’s most 
detailed dataset on how adults use formal and informal financial services. It offers insights into the financial behaviors and 
access to financial systems globally.

For more information, visit the [Global Findex website](https://www.worldbank.org/en/publication/globalfindex).
""")

# Main section logic
if option == "Home":
    # First display the Plotly globe with the title
    # Create the globe visualization
    economy_data = data['Country_Economy'].value_counts(normalize=True) * 100
    economy_df = economy_data.reset_index()
    economy_df.columns = ['Country_Economy', 'percentage']

    # Round the percentage to 2 decimal places for display
    economy_df['percentage'] = economy_df['percentage'].round(2)

    # Create a choropleth map using Plotly with a green color scheme
    fig = px.choropleth(
        economy_df,
        locations='Country_Economy',
        locationmode='country names',
        color='percentage',
        hover_name='Country_Economy',
        hover_data={'percentage': ':.2f'},  # Format hover data to 2 decimal places
        color_continuous_scale='Greens',
    )

    # Update hover text to add the percentage sign
    fig.update_traces(
        hovertemplate="<b>%{hovertext}</b><br>" +
                      "percentage=%{z:.2f}%<extra></extra>",
        hovertext=economy_df['Country_Economy']
    )

    # Add the title to the Plotly chart itself, making it bold and larger
    fig.update_layout(
        title=dict(
            text="FINDEX 2021 Data Visualizer",  # Title text
            font=dict(size=49, color='black', family="Raleway, sans-serif"),  # Stylish font and bigger size
            x=0.5,  # Center the title
            xanchor='center',
            y=0.95,  # Adjust positioning
            yanchor='top',
            pad=dict(t=20),  # Add padding to reduce space
        ),
        geo=dict(
            showframe=True,  # Show a frame around the map
            framecolor="black",  # Frame color
            showcoastlines=True,  # Keep coastlines visible
            coastlinecolor="Black",  # Set coastlines color to black
            projection_type='orthographic',  # Change projection to orthographic for a globe effect
            projection_scale=0.85,  # Zoom out more by reducing the scale
            center=dict(lat=10, lon=0),  # Center the globe around the equator
            lataxis_range=[-85, 85],  # Strictly limit the vertical dragging
            lonaxis_range=[-180, 180],  # Strictly limit the horizontal dragging
            oceancolor='lightblue',  # Set the color of the oceans
            showocean=True,  # Ensure oceans are displayed
        ),
        coloraxis_colorbar=dict(
            title="Participation (%)",
            len=0.5,
            thickness=15,
            tickvals=[0.5, 1, 1.5, 2],
            ticks="outside",
        ),
        width=1000,
        height=800,
        margin={"r":50,"t":50,"l":0,"b":0}
    )

    # Display the Plotly chart first
    st.plotly_chart(fig, use_container_width=True, config={'displayModeBar': False})

    # Now display the Financial Inclusion and Behaviour description
    st.markdown("""
    This application leverages the Global Findex 2021 dataset with over 140,000 participants to explore financial inclusion and behavior across various economies worldwide.
    
    Key features of this application include:
    - **Quick Visualization**: Instantly visualize the percentage of respondents from each country who participate in various financial services.
    - **Regional Analysis**: Explore financial trends and behaviors by country and region, identifying disparities in access to financial systems.
    - **Income-Based Analysis**: Analyze financial behaviors like savings, borrowing, and digital payments across different income levels.
    - **Gender-Based Analysis**: Compare financial inclusion patterns between genders, looking into variables such as account ownership, borrowing, and savings behavior.
""")

elif option == "Description of Variables":
    st.markdown("<h2 style='text-align: center;'>Descripton of Variables</h2>", unsafe_allow_html=True)
    st.markdown("""
- **Country_Economy**: The name of the country or economy.
- **Country_Code**: ISO 3-digit code representing each economy.
- **WorldBank_Region**: World Bank region classification (e.g., Sub-Saharan Africa, East Asia, etc.).
- **Adult_Population**: The population of adults (aged 15+) in the economy.
- **Respondent_ID**: A unique identifier for each respondent in the dataset.
- **Survey_Weight**: Survey weight for each respondent, used to make the sample representative of the population.
- **Gender**: Gender of the respondent (1 if female, 2 if male).
- **Respondent_Age**: Age of the respondent.
- **Education_Level**: Respondent’s education level from level 1 to 3.
- **Income_Quintile**: Income quintile of the respondent’s household.
- **Employment_Status**: Employment status of the respondent.
- **Account_At_Financial_Or_Mobile_Money_Provider**: Whether the respondent has an account at a financial institution or with a mobile money service provider.
- **Account_At_Formal_Financial_Institution**: Whether the respondent has an account at a formal financial institution.
- **Has_Debit_Card**: Has a debit card.
- **Used_Mobile_Money**: Whether the respondent used mobile money.
- **Paid_Bills_Online**: Made bill payments online using the Internet.
- **Sent_Money_To_Relative_Friend_Online**: Sent money to a relative or friend online using the Internet.
- **Bought_Something_Online**: Bought something online using the Internet.
- **Saved_For_Old_Age**: Saved for old age.
- **Saved_At_Formal_Financial_Institution**: Saved using an account at a financial institution.
- **Borrowed_For_Medical_Purposes**: Borrowed for medical purposes.
- **Borrowed_From_Formal_Financial_Institution**: Borrowed from a financial institution.
- **Borrowed_From_Family_Or_Friends**: Borrowed from family or friends.
- **Main_Source_Of_Emergency_Funds_30_Days**: Main source of emergency funds in 30 days.
- **Paid_Utility_Bill**: Paid a utility bill.
- **Received_Wage_Payments**: Received wage payments.
- **Received_Government_Transfer**: Received a government transfer.
- **Received_Government_Pension**: Received a government pension.
- **Financial_Worry_Old_Age**: Financially worried: old age.
- **Financial_Worry_Medical_Cost**: Financially worried: medical cost.
- **Financial_Worry_Bills**: Financially worried: bills.
- **Financial_Worry_Education**: Financially worried: education.
- **Saved_Money_Past_12_Months**: Saved money in the past 12 months.
- **Borrowed_Money_Past_12_Months**: Borrowed money in the past 12 months.
- **Received_Wage_Payment_And_Method**: Received a wage payment and method.
- **Received_Gov_Transfer_Or_Aid_And_Method**: Received government transfers or aid payments and method.
- **Received_Gov_Pension_Payments_And_Method**: Received government pension payments and method.
- **Paid_Utility_Bills_And_Method**: Paid utility bills and method.
- **Owns_Mobile_Phone**: Whether the respondent owns a mobile phone.
- **Has_Internet_Access**: Whether the respondent has access to the internet.
- **Made_Digital_Payment**: Whether the respondent made any digital payment.
- **Data_Collection_Year**: The year of the data collection.
""")

   # Main section logic for each page
if option == "Regional-Based Analysis":
    st.markdown("<h2 style='text-align: center;'>Regional-Based Analysis</h2>", unsafe_allow_html=True)
    st.write("This section allows you to explore financial trends and behaviors, including savings, borrowing, and digital payments, across various regions. You can compare how access to financial systems differs between regions and examine disparities in financial inclusion globally.")

# Create a dictionary mapping original column names to human-readable labels
    variable_labels = {
        'Account_At_Financial_Or_Mobile_Money_Provider': 'Account at Financial or Mobile Money Provider',
        'Saved_Money_Past_12_Months': 'Saved Money Past 12 Months',
        'Borrowed_Money_Past_12_Months': 'Borrowed Money Past 12 Months',
        'Paid_Bills_Online': 'Paid Bills Online',
        'Financial_Worry_Old_Age': 'Financial Worry Old Age',
        'Owns_Mobile_Phone': 'Owns Mobile Phone',
        'Has_Internet_Access': 'Has Internet Access',
        'Made_Digital_Payment': 'Made Digital Payment'
    }

    # List of regions from your dataset (assuming 'WorldBank_Region' column holds this data)
    regions = data['WorldBank_Region'].unique()

    # Multiselect for region selection
    selected_regions = st.multiselect("Select regions to compare", options=regions, default=regions[0])

    # Filter data based on selected regions
    regional_data = data[data['WorldBank_Region'].isin(selected_regions)]

    # Allow user to choose which variable they want to analyze (displayed without underscores)
    variable_to_compare = st.selectbox(
        "Select variable to analyze:",
        options=list(variable_labels.keys()),
        format_func=lambda x: variable_labels[x]  # Replaces underscores with spaces in dropdown
    )

    # Summarize the data for the selected regions and variable, including education level (educ_label)
    summary = regional_data.groupby(['WorldBank_Region', 'educ_label'])[variable_to_compare].mean().reset_index()
    summary.columns = ['WorldBank_Region', 'Education_Level', f'Average {variable_to_compare}']

    # Multiply the average by 100 to display percentages
    summary[f'Average {variable_to_compare}'] = summary[f'Average {variable_to_compare}'].mul(100).round(2)

    # Create an interactive Plotly bar chart to compare the regions and education levels
    fig = px.bar(summary, x='WorldBank_Region', y=f'Average {variable_to_compare}', 
                 color='Education_Level',
                 title=f"Comparison of {variable_labels[variable_to_compare]} Across Selected Regions and Education Levels",
                 labels={'WorldBank_Region': 'Region', f'Average {variable_to_compare}': f'Average {variable_labels[variable_to_compare]} (%)'},
                 barmode='group')

    # Update layout for better aesthetics
    fig.update_layout(
        xaxis_title="Region",
        yaxis_title=f"Average {variable_labels[variable_to_compare]} (%)",
        showlegend=True,
        width=800,
        height=500,
        margin={"r":0,"t":50,"l":0,"b":50},
    )

    # Show the chart in Streamlit
    st.plotly_chart(fig)

    # Summary of the analysis (formatting variable name)
    st.markdown(f"### Summary of Regional and Educational Insights")
    st.write(f"The analysis above shows how {variable_labels[variable_to_compare]} differs across regions and education levels.")
    st.write("Key takeaways:")
    for region in selected_regions:
        region_data = summary[summary['WorldBank_Region'] == region]
        for educ_level in region_data['Education_Level'].unique():
            avg_value = region_data[region_data['Education_Level'] == educ_level][f'Average {variable_to_compare}'].values[0]
            st.write(f"- In {region}, individuals with {educ_level} have an average {variable_labels[variable_to_compare].lower()} of {avg_value:.0f}%.")


elif option == "Income-Based Analysis":
    st.markdown("<h2 style='text-align: center;'>Income-Based Analysis</h2>", unsafe_allow_html=True)
    st.write("This section allows you to analyze financial behaviors such as savings, borrowing, and digital payments across different income levels.")

    # Create a dictionary mapping original column names to human-readable labels
    variable_labels_income = {
        'Account_At_Financial_Or_Mobile_Money_Provider': 'Account at Financial or Mobile Money Provider',
        'Saved_Money_Past_12_Months': 'Saved Money Past 12 Months',
        'Borrowed_Money_Past_12_Months': 'Borrowed Money Past 12 Months',
        'Made_Digital_Payment': 'Made Digital Payment'
    }

    # Select Income Quintile
    income_quintile = st.selectbox("Select Income Quintile:", data['Income_Quintile'].unique())

    # Filter the data based on the selected income quintile
    filtered_data_income = data[data['Income_Quintile'] == income_quintile]

    # Multi-select for financial indicators (displayed without underscores)
    selected_indicators_income = st.multiselect(
        "Select Financial Indicators to Analyze:",
        options=list(variable_labels_income.keys()),
        format_func=lambda x: variable_labels_income[x],  # Format options without underscores
        default='Account_At_Financial_Or_Mobile_Money_Provider'  # Default is financial account ownership
    )

    st.markdown(f"### Analysis for Income Quintile {income_quintile}")

    # Initialize a dictionary to store the summary for income analysis
    income_summary_dict = {}

    # Loop through selected indicators and create a chart for each
    for indicator in selected_indicators_income:
        # Normalize and calculate the percentage for the selected indicator
        income_indicator_chart = filtered_data_income[indicator].value_counts(normalize=True).mul(100).reset_index()
        income_indicator_chart.columns = [indicator, 'Percentage']

        # Get the percentage of people with the selected financial indicator
        has_indicator_income = income_indicator_chart[income_indicator_chart[indicator] == 1]['Percentage'].values[0] if 1 in income_indicator_chart[indicator].values else 0
        income_summary_dict[indicator] = has_indicator_income

        # Create a bar chart for each selected indicator (labels without underscores)
        fig_income = px.bar(
            income_indicator_chart,
            x=indicator,
            y='Percentage',
            title=f"{variable_labels_income[indicator]} for Income Quintile {income_quintile}",
            labels={indicator: variable_labels_income[indicator]},
            color=indicator,
            color_continuous_scale='Blues'
        )

        st.plotly_chart(fig_income)

    # Print out the summary text at the bottom for income analysis
    st.markdown("### Summary")
    for indicator, percentage in income_summary_dict.items():
        st.write(f"**{percentage:.1f}% of respondents in Income Quintile {income_quintile} have {variable_labels_income[indicator]}**.")


elif option == "Gender-Based Analysis":
    st.markdown("<h2 style='text-align: center;'>Gender-Based Analysis</h2>", unsafe_allow_html=True)
    st.write("Here you can analyze financial behaviors such as savings, borrowing, and digital payments for selected gender and age groups.")

    # Create a dictionary mapping original column names to human-readable labels
    variable_labels_gender = {
        'Account_At_Financial_Or_Mobile_Money_Provider': 'Account at Financial or Mobile Money Provider',
        'Saved_Money_Past_12_Months': 'Saved Money Past 12 Months',
        'Borrowed_Money_Past_12_Months': 'Borrowed Money Past 12 Months',
        'Made_Digital_Payment': 'Made Digital Payment'
    }

    # Gender selection
    gender = st.radio("Select Gender:", ("Female", "Male"))

    # Age group selection (assuming 'age_group' column is already in the dataset)
    age_group = st.selectbox("Select Age Group:", data['age_group'].unique())

    # Convert gender to appropriate coding (assuming female=1, male=2 in the dataset)
    gender_code = 1 if gender == "Female" else 2

    # Filter the data based on gender and age group
    filtered_data = data[(data['Gender'] == gender_code) & (data['age_group'] == age_group)]

    # Multi-select for financial indicators (displayed without underscores)
    selected_indicators = st.multiselect(
        "Select Financial Indicators to Analyze:",
        options=list(variable_labels_gender.keys()),
        format_func=lambda x: variable_labels_gender[x],  # Format options without underscores
        default=['Account_At_Financial_Or_Mobile_Money_Provider']
    )

    st.markdown(f"### Analysis for {gender}s in {age_group} Age Group")

    # Initialize a dictionary to store the summary
    summary_dict = {}

    # Loop through selected indicators and create a chart for each
    for indicator in selected_indicators:
        # Normalize and calculate the percentage for the selected indicator
        indicator_chart = filtered_data[indicator].value_counts(normalize=True).mul(100).reset_index()
        indicator_chart.columns = [indicator, 'Percentage']

        # Get the percentage of people with the selected financial indicator
        has_indicator = indicator_chart[indicator_chart[indicator] == 1]['Percentage'].values[0] if 1 in indicator_chart[indicator].values else 0
        summary_dict[indicator] = has_indicator

        # Create a bar chart for each selected indicator (without underscores in labels)
        fig = px.bar(
            indicator_chart,
            x=indicator,
            y='Percentage',
            title=f"{variable_labels_gender[indicator]} for {gender}s in {age_group} Age Group",
            labels={indicator: variable_labels_gender[indicator]},
            color=indicator,
            color_continuous_scale='Viridis'
        )

        st.plotly_chart(fig)

    # Print out the summary text at the bottom
    st.markdown("### Summary")
    for indicator, percentage in summary_dict.items():
        st.write(f"**{percentage:.1f}% of {gender}s in the {age_group} age group have {variable_labels_gender[indicator]}**.")
    
elif option == "Financial Recommender Engine":
    st.markdown("<h2 style='text-align: center;'>Financial Recommender Engine</h2>", unsafe_allow_html=True)
    
    # Define the enhanced_recommender function inside the elif block
    def enhanced_recommender(age, income_quintile, has_debit_card, uses_mobile_money, financial_goal, savings_habit, investment_interest):
        recommendations = []
        
        # Financial product recommendations
        if has_debit_card == "No":
            recommendations.append("Consider getting a debit card. Debit cards offer secure, convenient access to your money and can help you manage day-to-day transactions.")
        
        if uses_mobile_money == "No":
            recommendations.append("Mobile money services are a great way to manage transactions remotely and even save small amounts. Consider trying them for increased financial flexibility.")
        
        # Recommendations based on age
        if age < 30:
            recommendations.append("Starting early is key to long-term financial success! Focus on building a savings habit and avoid unnecessary debt.")
        elif 30 <= age <= 50:
            recommendations.append("This is the perfect time to focus on increasing savings and planning for long-term goals like buying a home or preparing for children's education.")
        elif age > 50:
            recommendations.append("As you near retirement, focus on low-risk investments and savings. Consider discussing retirement plans with a financial advisor.")
        
        # Recommendations based on income quintile
        if income_quintile < 3:
            recommendations.append("You might be eligible for government support programs or financial assistance tailored to lower-income groups. Explore these options to improve your financial stability.")
        else:
            recommendations.append("With a higher income level, consider diversifying your investments, including retirement savings and possibly high-return investments like stocks or real estate.")
        
        # Financial goals recommendations
        if financial_goal == "Retirement":
            recommendations.append("It's important to have a solid retirement plan. Focus on long-term, stable investments like pension funds or bonds.")
        elif financial_goal == "Home Ownership":
            recommendations.append("Buying a home is a big goal. Consider saving aggressively or exploring mortgage options to make your goal achievable.")
        elif financial_goal == "Education":
            recommendations.append("Education savings can benefit from high-interest savings accounts or tax-advantaged education accounts.")
        
        # Savings habit recommendations
        if savings_habit == "No":
            recommendations.append("Starting a savings habit, even if it's a small amount each month, can build your financial security over time.")
        else:
            recommendations.append("Good job on saving! Consider increasing the amount or exploring higher-yield savings accounts or investments.")
        
        # Investment interest recommendations
        if investment_interest == "Yes":
            recommendations.append("Since you're interested in investing, explore stocks, mutual funds, or real estate. A financial advisor can help you find the right options.")
        else:
            recommendations.append("If you're unsure about investing, start small with safer options like government bonds or index funds.")
        
        return recommendations

    # Collect user inputs
    age = st.slider("Your Age", 18, 70, 30)
    income_quintile = st.slider("Income Quintile (1 = Lowest, 5 = Highest)", 1, 5, 3)
    has_debit_card = st.radio("Do you have a debit card?", ("Yes", "No"))
    uses_mobile_money = st.radio("Have you used mobile money?", ("Yes", "No"))
    financial_goal = st.radio("What is your main financial goal?", ("Retirement", "Home Ownership", "Education"))
    savings_habit = st.radio("Do you have a savings habit?", ("Yes", "No"))
    investment_interest = st.radio("Are you interested in investing?", ("Yes", "No"))

        # Initialize recommendations as an empty list
    recommendations = []

    if st.button("Get Recommendations"):
        # Call the enhanced_recommender function and generate recommendations
        recommendations = enhanced_recommender(age, income_quintile, has_debit_card, uses_mobile_money, financial_goal, savings_habit, investment_interest)

    # Check if the recommendations were generated successfully and display them
    if recommendations:
        st.markdown("### Recommendations:")
        for rec in recommendations:
            st.write(f"- {rec}")
    else:
        st.write("Click the 'Get Recommendations' button to receive personalized financial recommendations.")

elif option == "SML Classification":
    st.title("SML Classification - Financial Prediction")

    # Collect user inputs for prediction
    st.markdown("### Provide the details to predict the financial product:")
    age = st.slider("Your Age", 18, 70, 30)
    income_bracket = st.selectbox("Income Bracket (1 = Lowest, 5 = Highest)", [1, 2, 3, 4, 5])
    has_internet_access = st.radio("Do you have Internet Access?", ["Yes", "No"])
    employed = st.radio("Are you employed?", ["Yes", "No"])
    high_income_region = st.radio("Are you in a High Income Region?", ["Yes", "No"])
    
    # Convert user inputs to a DataFrame
    input_data = pd.DataFrame({
        'Age': [age],
        'Income Bracket': [income_bracket],
        'Has Internet Access': [1 if has_internet_access == "Yes" else 0],
        'Employed': [1 if employed == "Yes" else 0],
        'High Income Region': [1 if high_income_region == "Yes" else 0]
    })

    # One-hot encode the categorical features
    input_data_encoded = ohe.transform(input_data)

    # Make prediction
    if st.button("Predict"):
        prediction = xgb_model.predict(input_data_encoded)
        st.write(f"Prediction: {prediction[0]}")