Gowthamvemula commited on
Commit
39f4a77
·
verified ·
1 Parent(s): 1884e89

Update pages/3_EDA_and_Feature_Engineering.py

Browse files
pages/3_EDA_and_Feature_Engineering.py CHANGED
@@ -596,8 +596,128 @@ Customers who exited (especially "Inactive - Exited") tend to have a lower age r
596
 
597
  ''')
598
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
 
 
 
600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
 
602
 
603
 
 
596
 
597
  ''')
598
 
599
+ st.write('# Multivariate Analysis')
600
+ st.write("### Correlation Heatmap with Multiple Features")
601
+
602
+ # Calculate the correlation matrix for more columns
603
+ correlation_matrix = df[['age', 'tenure', 'estimatedsalary', 'creditscore', 'balance', 'hascrcard']].corr()
604
+
605
+ # Create the heatmap
606
+ fig, ax = plt.subplots(figsize=(8, 6)) # Set the figure size
607
+ sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt='.2f', annot_kws={'size': 12}, ax=ax)
608
+
609
+ # Set the title
610
+ ax.set_title('Correlation Heatmap', fontsize=14)
611
+
612
+ # Display the plot in Streamlit
613
+ st.pyplot(fig)
614
+ st.markdown('''
615
+ ### Insights from heatmap:
616
+
617
+ - **Independence of Variables:** Variables like age, balance, creditscore, and tenure show minimal correlation, suggesting they don't significantly influence each other.
618
+
619
+ - **Weak Relationships:** For example, hascard has almost no relationship with other variables, meaning it may not directly impact features like balance or estimatedsalary.
620
+ ''')
621
+ st.write("### Grouped Data by Geography and Exiting Category")
622
+
623
+ # Group the data by Geography and Exiting Category
624
+ grouped_data = dfc.groupby(['geography', 'exiting_category']).agg({
625
+ 'creditscore': 'mean',
626
+ 'balance': 'mean',
627
+ 'estimatedsalary': 'mean',
628
+ 'age': 'mean'
629
+ }).reset_index()
630
+
631
+ # Display the grouped data in a table
632
+ st.dataframe(grouped_data)
633
+ st.write('''
634
+ ### Insights for Grouped Data by Geography and Exiting Category
635
+
636
+ 1. **Geography Influence on Customer Behavior**:
637
+ - The **creditscore**, **balance**, **estimated salary**, and **age** of customers may vary significantly across different geographies. For example, if one geography has a higher average **balance** and **estimated salary**, it could indicate wealthier customers in that region.
638
+
639
+ 2. **Exiting Category Patterns**:
640
+ - The **exiting_category** can show patterns of customer churn. For instance, if the average **creditscore** is significantly lower for customers who exited, it could indicate that customers with lower scores are more likely to leave.
641
+ - Similar insights can be made for **balance** and **estimated salary**. Customers with lower balances or salaries might be more prone to churn.
642
+
643
+ 3. **Age Distribution**:
644
+ - By analyzing the **age** column, you might find that younger or older customers are more likely to exit. If younger customers have a lower average age in the exited category, businesses may need to focus on improving retention strategies for that demographic.
645
+
646
+ 4. **Geography and Exiting Correlation**:
647
+ - If you notice certain geographies have higher **exiting_category** proportions (e.g., more exits in one region), it could indicate regional issues or dissatisfaction that need to be addressed.
648
+
649
+ 5. **Targeted Strategies Based on Grouping**:
650
+ - Businesses can develop **targeted marketing or retention strategies** based on this grouping. For example, focusing on high-creditscore customers in a specific region to reduce churn, or providing more incentives for customers in low-income areas.
651
+
652
+ ### Actionable Strategies Based on Insights:
653
+
654
+ 1. **Customer Segmentation**: Use the insights to segment customers based on their geography and behavior (e.g., exited vs. retained), and tailor marketing or retention efforts for each group.
655
+ 2. **Improvement of Customer Retention Programs**: If exiting customers tend to have lower balances or salaries, businesses could offer more targeted retention strategies (e.g., loyalty rewards, personalized offers).
656
+ 3. **Localized Marketing Campaigns**: If certain geographies show higher churn, localized campaigns addressing the concerns specific to those areas can be launched.
657
+
658
+ ''')
659
+
660
+ st.write("### Average Balance by Geography and Exiting Category")
661
+
662
+ # Create the pivot table
663
+ pivot_table = dfc.pivot_table(
664
+ index='geography', columns='exiting_category',
665
+ values='balance', aggfunc='mean'
666
+ )
667
+
668
+ # Create the heatmap
669
+ fig, ax = plt.subplots(figsize=(8, 6)) # Set the figure size
670
+ sns.heatmap(pivot_table, annot=True, fmt=".2f", cmap="YlGnBu", ax=ax)
671
+
672
+ # Set the title
673
+ ax.set_title("Average Balance by Geography and Exiting Category")
674
+
675
+ # Display the plot in Streamlit
676
+ st.pyplot(fig)
677
+ st.markdown('''
678
+ **1. Geography Insights:**
679
+
680
+ **Germany:**
681
+ - Customers in Germany have the highest average balances across all categories (~119,000–120,000).
682
+ - This suggests German customers may hold larger accounts or higher financial engagement with the bank.
683
+
684
+ **France:**
685
+ - French customers have lower average balances (~59,000–72,000) compared to Germany, with some variation between Active/Exited and Exited/Not Exited categories.
686
 
687
+ **Spain:**
688
+ - Spanish customers fall in the mid-range, with average balances between ~56,000–77,000, slightly higher than France but significantly lower than Germany.
689
 
690
+ **2. Customer Status Insights**
691
+
692
+ **Exited Customers:**
693
+ - Exited customers in all geographies (France, Germany, Spain) tend to have slightly lower balances than their active counterparts.
694
+ Exception: In France, exited customers have balances slightly higher than active ones in the "Exited" categories, which could indicate retention issues with higher-value customers.
695
+
696
+ **Not Exited Customers:**
697
+ - Customers who have not exited generally hold higher balances, particularly in Germany and Spain.
698
+ Suggests that customers with higher balances are more likely to remain loyal.
699
+
700
+ **3. Geography-Specific Observations:**
701
+
702
+ **France**:
703
+ - Active and non-exited customers have higher balances (72,622) compared to their exited counterparts (59,780–61,009).
704
+
705
+ **Germany**:
706
+ - **Insight**: Little variation in average balances across all categories (~119,000–120,000). This indicates a consistently high-value customer base regardless of status.
707
+
708
+ **Spain**:
709
+ - **Insight**: The largest variation is seen in Spain. Non-exited customers (77,529) have much higher balances than exited customers (56,480).
710
+ - This suggests a significant difference in engagement between customer segments in Spain, indicating that non-exited customers may be more engaged or satisfied with the service compared to exited customers.
711
+
712
+ **Key Takeaways**:
713
+ - **Germany** holds the most high-value customers with consistently high balances.
714
+ - **France** shows retention issues, as exited customers can still hold moderate balances.
715
+ - **Spain** shows the largest difference in balances between exited and non-exited customers, indicating potential for targeted retention efforts.
716
+
717
+ **Retention Opportunity**:
718
+ - Focus on retaining high-value customers in **Spain** and **France** to improve loyalty.
719
+
720
+ ''')
721
 
722
 
723