<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Piyush Kashyap on Medium]]></title>
        <description><![CDATA[Stories by Piyush Kashyap on Medium]]></description>
        <link>https://medium.com/@piyushkashyap?source=rss-db8d4ee3b433------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*noFbQq7MSuGlImJkyB5Czw.png</url>
            <title>Stories by Piyush Kashyap on Medium</title>
            <link>https://medium.com/@piyushkashyap?source=rss-db8d4ee3b433------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 22:59:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piyushkashyap/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Churn Prediction for Credit Card Customers]]></title>
            <link>https://medium.com/@piyushkashyap/churn-prediction-for-credit-card-customers-c7d35221680b?source=rss-db8d4ee3b433------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7d35221680b</guid>
            <category><![CDATA[xgboost]]></category>
            <category><![CDATA[iim-bangalore]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[projects]]></category>
            <category><![CDATA[mlops]]></category>
            <dc:creator><![CDATA[Piyush Kashyap]]></dc:creator>
            <pubDate>Sun, 05 Dec 2021 17:37:21 GMT</pubDate>
            <atom:updated>2021-12-05T18:23:34.567Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Authors</strong></h3><p><a href="https://www.linkedin.com/in/robin-raj-265167136/">Robin Raj</a> | <a href="https://www.linkedin.com/in/danish-usmani-0ba28a199">Danish Usmani</a> | <a href="https://www.linkedin.com/in/priyanka-dalmia">Priyanka Dalmia</a> | <a href="https://www.linkedin.com/in/piyushkashyap97/">Piyush Kashyap</a></p><h3>Important Links</h3><ol><li>Link to GitHub Repository — <a href="https://github.com/apollo-robin/customer-churn">https://github.com/apollo-robin/customer-churn</a></li><li>Dataset from Kaggle (<em>Credit to Sakshi Goyal, Software Engineer, Wipro</em>) — <a href="https://www.kaggle.com/sakshigoyal7/credit-card-customers?select=BankChurners.csv">LINK</a></li><li>Data Profile Report using Panda’s Profiling Tool — <a href="https://htmlpreview.github.io/?https://github.com/apollo-robin/customer-churn/blob/main/Reports/credit_card_profile.html#overview-dataset_overview">LINK</a></li><li>Here is the link to the hosted service on Streamlit — <a href="https://share.streamlit.io/apollo-robin/algo_server/main/server.py">https://share.streamlit.io/apollo-robin/algo_server/main/server.py</a></li></ol><h3>Project Scope &amp; Problem Statement</h3><p>Banks and financial institutions have a large number of consumers in today’s business climate. ATMs, debit cards, credit cards, online banking, and other channels are used by banks to deliver services. The number of clients has exploded, and they are becoming increasingly aware of service quality. Customers are shifting from one bank to another for a variety of reasons, which fosters fierce rivalry among banks.</p><p>Hence, as a part of this project, we develop &amp; deploy a model which can predict which customer is likely to churn out based on the customers’ demographic, psychographic and historical transactional data, catering to a pressing need for such solutions in Financial Solutions Market in general and Credit Card Service Providers in specific. The prediction can assist banks in identifying who is likely to leave, why they are leaving, and what they should do about it.</p><h3>Dataset Overview &amp; Data Profile Report</h3><p>Dataset has <strong>20 input features</strong> for more than <strong>10k customers</strong>, which consists of <strong>14 Numerical Features, 5 Categorical Features &amp; 1 Boolean Feature</strong> with a target variable as Attrition or Churn Flag denoting Existing or Attrited Customer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U6jiPftBRX6YQLMOuE2X6w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2OuK8zsPJexvjWy5UQx1yw.png" /></figure><p>Panda’s Data Profile Report was created to understand the nature of each available feature. For Univariate analysis, a detailed report on individual features was used to find imbalance &amp; missing values.</p><p>From the top right corner above, snapshots show the distribution of Gender, Marital Status, Card Category, Age, Income Category &amp; Education Level. Though there is a lower number of females in the dataset there is no significant skew towards any gender. The dataset contains a very low representation of non-blue type cardholders, divorced, college-goers &amp; richer individuals.</p><p>For Bivariate analysis, Pearson’s Correlation Heat Map for numerical features showed that the “Average Open to Buy” is highly correlated to “Credit Limit”, which clearly shows that the higher the credit limit of a customer, the higher will be it&#39;s open to buying credit line and only one of these should be further used for analysis. Spearman’s Correlation for Categorical Features showed some positive correlation between gender and Income Category, which shows the inherent bias in the society that male’s income is higher compared to females.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*BXyuF2sQxST5tGzRc4r4KA.png" /></figure><h3>Data Pre-Processing</h3><p>With the help of the findings from the Data Profile Report, we implemented three data processing steps. First, to avoid a large number of Dummy Variables using <strong>One Hot Encoding</strong>, we implemented <strong>Target Encoding</strong> for some of the categorical variables “Education Level”, “Income Category” &amp; “Card Category”. For categorical variables with just two possible values like, “Gender” &amp; “Marital Status”, we implemented One Hot Encoding. For some of the numerical features “Total Revolving Balance”, “Average Open to Buy” &amp; “Total Transaction Amount”, we implemented Feature Binning, to introduce some non-linearity in the model for better performance.</p><p><strong>K Nearest Neighbors (kNN) Imputation</strong> was implemented for the categorical features “Education Level”, “Marital Status” &amp; “Income Category” so that we do not have to remove any of those records from the dataset.</p><p>We also noticed that the training dataset was highly imbalanced with the positive class of attrited customers being very less compared to the negative class of existing customers. Since the class we are interested in, i.e., the attrited class is rare, we used <strong>SMOTE Sampling</strong> to handle this imbalance as it generates synthetic samples for the minority class and the trained model will then not be biased. Post this processing, we stored the dataset in pickle format.</p><h3>Experiment Tracking, Best Model &amp; Feature Selection</h3><p>We implemented various models and used Weights &amp; Biases for Experiment Tracking. Please find the summary of all the experiments. 80:20 split was used for Train-Test Dataset.</p><p>We used Grid search for hyperparameter tuning with 5 Cross-validation. <strong>XG Boost Model </strong>provided the best Accuracy, F1 Score, Precision, Recall &amp; Final Classification Score values, hence we went forward with <strong>XG Boost Model</strong>. Also, it came out to be the best performing model as per ROC &amp; Precision vs Recall Curves for all the experiments in W&amp;B.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jAUwQb6ioZRtqqybYix4oQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*leo6Z9t6JpAu0IY1glbu-w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*HdGn9h_aGHUNICFxswyq6g.png" /></figure><p>Model-based Feature selection as Embed Method was used, where the top <strong>10 features</strong> in the order of importance as shown in the table were considered further. XG Boost model was retrained using these top 10 features only, with the help of Grid Search for hyperparameter tuning. One Standard Rule was used to select the best set of hyperparameters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*9WvOztipEd4GUNzZbe5xHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*B7ArM7TGZLY6NfE9o45B1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f8AO4nahvR5ynigrBsvnAg.png" /></figure><h3>Model Deployment</h3><p>The final retrained XG Boost model with 10 features was then deployed as a web application. For this purpose, the model was first saved as a pickle file. Then, the Model-in-Service strategy was used to deploy the model such that it gets embedded into the application. <strong>Streamlit</strong> hosting service was used for deployment. Given below are the snapshots of the designed User Interface for multiple scenarios:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWbfuDzU3Bqp_gzUMeQoLA.png" /></figure><h3>Model Monitoring</h3><p>To assess the quality of predictions and figure out whether retraining is needed, we monitored the model drift and generated a data drift report using the <em>evidently</em> library. Given below is the snapshot of the report.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*S8RiaUMFpZkedU9_u_86Hg.png" /></figure><p>Drift was detected for <strong>81.8%</strong> of the features i.e., <strong>9 out of 11</strong> features in the production set did not follow the same distribution as the training set. We also calculated the classification performance report to understand the impact of data drifts on model performance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/496/1*Py-oXHCwAR1iyiLQZhoQBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*2uRP93CNfwwKSw2O1RYmCw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*ox5snWJh2o9a6LXpXe0rdA.png" /></figure><p>The model performance decays on the production set as compared to the reference set. Performance across all four metrics has declined. This is possible because the production set is poorly sampled since the positive class is under-represented in the production set.</p><h3>Model Monitoring — Sub-Segment Error Analysis on Gender</h3><p>We compared the accuracy and other metrics of the model across the two gender categories. The model did not show relevant drift from the reference model in both the male and female categories.</p><p>Results of model drift in the ‘<strong>MALE</strong>’ category:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*BKEtnoa_g0HIgftOW4_bKQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*6PAuDg-KpnBftNsPW85lBA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*XlVS9A6gpfrwaZmnRCKBRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/406/1*WbeBYmppIJm4lBcmyvyLfw.png" /></figure><p>Results of model drift in the ‘<strong>FEMALE</strong>’ category:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*bGofzttiatF1SOM2BLgNcQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*nZfWobrpoxVkGeQLEMpdPA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*i7LfVTjjIRZ7ZvmTu_kSWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*CWG6W6IGSWZbiMeBnGn54g.png" /></figure><h3>Model Explanation</h3><h4>Global Interpretation</h4><p>Using the <strong>Shapley Values Summary</strong>, we can interpret that Total transaction count is the most important factor while gender is the least important factor. A low <strong>Total Transaction Count</strong> indicates more attrition. A high <strong>Total Transaction Amount</strong> indicates low attrition. Using the <strong>Partial Dependency Plot</strong>, we can interpret that as the <strong>Total Transaction Count</strong> increases the probability of attrition decreases. Similarly, a higher <strong>Relationship Count</strong> indicates less attrition.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*y58VM0yOtDdpQ25o5_T1DQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*SZZp6dPVoDCoJDXBLGxSjA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*egh2LbNXiQmTlczl6cAKEw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*pG63r423TcdgRt1E7-bFdw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*GCtcFKGOTq7x-Si_VSM6gg.png" /></figure><h4>Local Interpretation (Scenario 1)</h4><p>Using <strong>LIME</strong>, we can explain the case of No attrition with a probability of 0.62. The features value which contributes towards no attrition are: Low revolving balance, low average utilization ratio, etc. We have also examined cases of attrition with a probability of 1.00. Using<strong> SHAP, </strong>we can see that the features value which contributes towards no attrition are: Change in Transaction Count (Q4 over Q1), total relationship count, etc. These features push away from the base value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*YO3mDt7cEJx6ingMUtClTw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*H3AVQDTBJCVeKuDFiBUw4Q.png" /></figure><h4>Local Interpretation (Scenario 2)</h4><p>Using <strong>LIME</strong>, we can explain the case of attrition with a probability of 1.00. The features value which contributes towards attrition are: Poor relationship count, high value of Inactive Months in last 12 months, etc. Using<strong> SHAP, </strong>we can see that the features value which contributes towards attrition are: Low revolving balance, low total transaction count, etc.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*XxBBobF2YnE7Erpekwr9eA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*WD3MPCkz-QNjxMkWvfSygA.png" /></figure><h3>Model Calibration Plot</h3><p>This plot is used to measure model reliability. As per the plot, Final XG Boost model is not near to perfect calibration but can be considered as a reliable model for churn prediction.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*Nq5wt2TYf_R0RrHiyg-KTw.png" /></figure><h3>Model Reporting — Model Card</h3><p>Below is a snapshot of the Model Card with a summary of the machine learning model. Model performance and accuracy difference for Male and Female Segment prediction was reported.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*w1toIZaJI6p9KmjcOnfKcw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*9rQEZ0n62rKBrKhKqX6Xmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*XtqtiOYDIxIhI4S3e-2lkg.png" /></figure><h3>GitHub File Structure</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/1*MqKIWUHfhDVNkDnEQJrE5Q.png" /></figure><p>To maintain our project resources in a structured way, we used GitHub as a version control system. As we can observe in the project directory tree diagram, we have a <strong>Readme</strong> file to describe the project not limited to the problem statement. Apart from that, there are 5 directories to store different types of resources. <strong>Datafiles</strong> consist of all raw &amp; processed data files used in test, train &amp; validation. <strong>Models</strong> directory stores the model in the pickle file format. <strong>Notebook</strong> folder directory consists of all the python notebook files used in the project like data processing, model development, model deployment &amp; model monitoring. <strong>Python/Files</strong> folder consists of the code used to create &amp; host web application UI for project demo purposes. Finally, the <strong>Reports</strong> folder directory consists of all HTML reports like Model cards, data profile reports from pandas, data drift monitoring reports, model classification performance reports, sub-segment accuracy analysis on gender reports, and others. GitHub also enabled collaborative work among group members.</p><h3>Challenges &amp; Key Lessons</h3><ol><li>In order to select the best-performing model, we consider different evaluation metrics like accuracy, precision, recall &amp; F1 Score. We finalized on using the F1 score as both FN and FP had equal-cost considerations.</li><li>It was challenging to accommodate multiple contributors from the group for the GitHub code repository, which gave birth to multiple conflicts throughout the development process. We learned to resolve those conflicts, create multiple develop branches, pull requests &amp; merge them to the main branch periodically.</li><li>We have incorporated Model-In-Service as a deployment strategy for the model in our project for simplicity in the learning phase. We understand all the challenges with this strategy like tight coupling between the model &amp; the application, making it tough to avoid downtime during model updates, etc.</li><li>We learned the methodology &amp; importance of showcasing our projects by creating a well-curated Medium Article with all relevant content.</li><li>We understood the importance of studying and reporting inherent bias in the model for segments like the Male/Female gender to facilitate the derivation interpretations of the results.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7d35221680b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>