 So this talk is just one of the more interesting talks, I think, personally speaking. I'm looking forward to and it's special for another reason because this is one of the few talks which has two speakers who have proposed a talk out of which Padmaja will be speaking today and she's currently working as a software developer at VMware. She's given a lot of talks before as well at Picon US 2017-2018 and at Picon India 2016. She is currently working on a product that enhances customer serviceability by providing proactive recommendations. It's a lot of words but I'm sure she'll elaborate at some point. And she's a data science enthusiast with a strong passion for dance and loves going on adventurous trips. Nice to meet you Padmaja. The second speaker is Bhargava and he's spent the last 17 years helping businesses both large and small use data algorithms to build a moat. He's worked on large scale machine learning problems in transportation, banking, software and networking products. His previous startup was incubated by SAP. Currently he's working at Benize which he co-founded and he's focused on helping small and medium sized e-commerce companies improve conversion. He's presented a talk and workshop in SAP USA, SAP India and Picon India in the past and he's also a good friend. So I'm very happy to be part of this stage and see how the talk will go on, which I haven't mentioned the title of. The talk is let's build a no code tool for small businesses to reduce churn. So I think we are at the 550 mark and Padmaja, the stage is yours. Very good evening to all. I'm really excited to be a part of this year's Picon India edition. I'm sure it's going to be one of the most adventurous version of Picon till date. So disclaimer notice, please excuse me if there are any technical glitches during the presentation. We hope there aren't any. So with that said, today we'll be looking into one of the most interesting topics called as churn analysis. And how in the next 20 minutes you can build an end to end tool which can be used by anyone to perform churn analysis. So before I start talking all nerdy, here is a small introduction about us. So I'm Padmaja Bhagwat, a huge data science enthusiast and a software developer at VMware. So here I work for a team that enhances the customer service ability by providing proactive alerts and recommendations to our customers. And Bhagwat here is a deep learning engineer. He has been early data scientist at many top notch companies and currently he is a founder and CTO at Binaz. And to be honest, he is one of the biggest inspiration for me to be in the stream of data science. So enough about us. So let's get directly started with the talk. So this is how the outline of the talk is going to look like. We'll start off with providing the business context behind this problem. We'll also look into the different steps that are being followed to perform churn analysis. Then we'll look into the architecture of the tool that we're building today. And finally, if everything goes as expected, I'll promise you a very awesome demo towards the end of it. So let's get started. So we have seen that COVID-19 has had a huge negative impact on the businesses, especially on the small scale businesses. And most of them have now moved online. And at this point of time, it is extremely important for these businesses to ensure that most of their customers are sticking with their product for as long as possible. So in this highly competitive online world, businesses cannot settle for reactive approach where they first wait for the customer to abandon their product, and only then they start taking some actions. It is high time we start taking some proactive actions where we perform everything that we can in order to retain the customers for as long as possible. So before we dive into the exact steps that are being followed to perform churn analysis, let's zoom out a little bit and see how exactly the customer engagement lifecycle looks like. So it starts off with you advertising your product, thereby increasing the awareness of the product among the potential customers. Then those potential customers, they start engaging with the product. They start exploring the features. They really like the features that you're providing. So they even get converted into paid customers. Now you expect those customers to remain loyal to your product for the rest of their lives. Now this is what you ideally expect to happen, but real world is never ideal, right? So that's why there are different phases where your customers might start disengaging from your product. And the first kind of disengagement is called as customer abandonment. So in this case, the customer is really impressed with the advertisement that you have put out. So they come and they explore the different features that you're providing, but after that point, they never really come back. So once, after this kind of disengagement, there's yet another kind of disengagement called as customer attrition. So here, the customers seem to be really interested in your product. Therefore, they even sign up for the free trial version. But after that trial period gets over, they never really come back. Now again, this is called as customer attrition. And the third and the worst kind of customer disengagement is called as job. So in this case, the customer is the customer whom you thought was loyal, the customer who was using your product for many, many years, all of a sudden stopped using the product one day. Now this has a huge negative impact on the business because you would have already invested so much of your time and energy trying to nurture this customer, trying to get this customer onboarded for as long as possible. But if the stock using your product all of a sudden, it has a huge negative impact on the business. And this is what we will be focusing on in today's talk, how we can avoid this exact same situation. Because we all can agree that it is much less expensive to retain existing customers than to acquire new ones. So the tool that we will be building today helps us identify this exact phase where the customer, the active customer transitions from being active to being at risk of churning the system forever. So our product will help you understand the exact timeframe when this transition is happening. So since the beginning of the talk, I've been telling that it's extremely important to perform churn analysis. So now that we have established that it's important to perform timely churn analysis, let's look into the exact steps that are being followed in order to perform the churn analysis. So the first and the obvious step is that you have to pre-process your data. You have to convert it into the format that your machines can understand. Then we'll be discussing various different models that can be used in order to perform churn analysis and how you can derive predictions out of the model that you have built. And finally, we'll be building a super cool web application to visualize the entire analysis that we have done in the previous three steps. So for this presentation, we have used an openly available data site called as telecom churn, which you can easily download from Kaggle. So here, I have just picked a few features, but in reality, the data has a lot more features to it. Let me tell you, you can easily extend the steps that I will be talking in the next slide to any kind of data as long as you ensure that your data has these three features. First is you need to ensure that your data has customer ID, which is the unique identifier for your customer. Then you need to ensure that the data has this churn column, which says whether the customer has churned or not, which is obvious because you are doing churn analysis and we need to have this column for sure. And finally, the most important feature that you need to ensure that ensure is this tenure. Now, this tenure period means slightly different for different people. For the customers who have already churned, let's say for this third customer, this tenure period of two months indicate that the customer has used the product only for two months. So the entire lifetime of the customer with the product was just two months. But whereas for the customer who has not yet churned, this tenure period of 34 indicates that the customer has been using the product from past 34 months and will continue using the product in the future. So there's a subtle difference between these two, but I think it's really important to understand in order to do the correct kind of prediction. So as long as you ensure that these three features are there, remaining all features can be anything depending on the kind of business you are into. So again, depending on the type of data, you can perform different kind of preprocessing steps on it. In this case, as you can see, most of the features are categorical. So we'll be going with the simple one-hot encoding. And find us provides this very handy function called as pd.getDummies, where you just have to send all the categorical features and boom, it creates the entire column of one-hot encoded features. So again, if your data contained time series data, which talked about the way your customer purchased with your product, you can probably use this TSFresh package, which will help you create the features out of your time series data. Now, again, depending on your data, you go ahead with different kind of preprocessing. In this case, we are sticking to a very basic kind of preprocessing, which is creating one-hot encoding out of the categorical data. So once we have converted the data into the format that can be understood by the model, let's explore the different ways that we can use to build the model. So by looking at the data, you think that this is a straightforward classification task. So you can think that I can use a simple decision tree or logistic regression to perform this churn classification, which is great. These models will tell you whether the customer is going to churn or not, and will also give you the probability with which the customer is going to churn. But all that you are looking for in here is, you're trying to build a model, which can tell you at what exact point of time the customer is going to churn, because you want to take the actions at the correct point of time. And that's when the survival analysis models come into picture. So there are different kinds of survival analysis models, but for this presentation, we will be sticking to the Cox Proportional Hazard model, which is the most popular one in the survival analysis model. So again, Python provides this very useful package called as LifeLanes, where you can play around with different kinds of survival analysis models. So as I told before, you can see in this plot, on the x-axis you have tenure period, and on the y-axis you have the survival chances of the customer. So you can see that the survival chances of 1 indicates that the customer has lapping the product and will stick with the product for a very long time. Whereas the survival chances of 0 indicates that the customer is going to churn for sure. So in between these two periods, from the time the survival chances of the customer reduces from 1 to 0, you need to take some action. You need to send some offer to something so that you can increase the lifetime of the customer with your product. So this is exactly why we are going with survival analysis models. It tells you the exact time when the specific event is going to happen. So let's see how exactly we can build this using Python. Although the concept might look a little complicated, you can see how easy it is to build this model using Python. So all you have to do is you have to import Coxfitter from this very famous lifelines package. I highly recommend you to go ahead and use this package. So once you have imported the model, you just have to split your data into training and testing, and you have to initialize the model. And you just have to do model.fit and you have to send the training data as the first parameter and then the duration column. In our case, it's 10-year as the second parameter. And finally, the event column, which in our case is whether the customer is going to churn or not. So you just have to follow these three simple line of code in order to build your churn analysis model. So it is as simple as that. So after you have built this model, if you do model.plot, it will exactly tell you how important each feature in your dataset is. So on the X-axis, you can see the hazard ratio. Just think of it as some coefficient, all right? And on the Y-axis, you can see the exact features that are being used to train the model. So all you have to remember is, hire the hazard ratio, hire the chances of customer churning out, which is not what we want. We want the exact opposite. We want our customers to stick with the product for a very long time. That's why we focus on the features that has the lesser hazard ratio, right? In our case, these are the last four features has a very low hazard ratio. So now let's just pick one of the features, which is total charges, and see how changing this feature impacts the survival chances of our customer. So you can see the total charges has decent hazard ratio of zero. So now let's see how it impacts the survival chances, right? So all you have to do is, you have to do model.plot partial effects on outcome and just send the feature that you're interested to learn about. So here you can see the black dotted line indicates the baseline survival curve of the dataset. Now by some chance, if you just reduce the total charges in the dataset to zero, you can see the survival curve has moved towards the left, which means the chances of customer surviving is dropping down rapidly and it is dropping right from the 10th month itself. Whereas if you increase the total charges to 4,000, you can see that the customer is sticking with the product for a very long time, right? Only after 60th month, this chances start reducing. So which is obvious, right? If the customer is spending too much, if the customer is spending a lot on your system, then it is obvious that the customer is going to stick with the product for a very long period of time. That is what this graph is telling us. So now that we have built a model and we have seen how each feature impacts the survival chances, let's do the exact prediction. We need to know at what exact point of time a given customer is going to churn out so that we can take a relevant action before that, right? So for that, we will be looking at only those customers who have not yet churned. The customers who have already churned, you cannot really do anything about that. So for the customers who have not yet churned, they are called a censored subject. So all you have to do is you just have to do model.predictSurvival function and send the censored subject as an input. That is the entire prediction of when the customer is going to churn. So this is how the graph looks like. The dotted line, what it indicates is the survival chances of this specific customer and how it is varying over the period of time. You can see at 40th month, the customer will definitely churn out. But there is a slight issue with this prediction that the model has given. The model thinks that the tenure period of 22 months is the total lifetime of this customer with the product. Which is not true. As I had mentioned before, for the customers who have not yet churned, this just, tenure period just indicates that the customer has been using the product from past 22 months and will continue using the product. Therefore, till 22nd month, you are for sure you know that the customer has been sticking to the product, right? Therefore, you have to condition your prediction by dividing each one of the value with the tenure period. So now you get this bold line. Here you can see that till 22nd month, the survival chance of customer is extremely high, which is one. Only after that, it starts reducing. All right? So here we have seen how the survival curve of the customer is varying over different period of time. Now if you want to take some action, let's say you would want to send some offer when the survival chance of the customer reduces by 50%, then Python provides this very simple function again called as queued survival times. So using this queued survival times from the lifelines package, all you have to do is you have to send a percentile and you have to send a conditioned graph that we got in the previous plot as an input. And there you go. You will get the exact month when the survival chances of this customer reduces by 50%. So you can see that at 30th month, the survival chance of the customer has reduced to 50%. And you can see the remaining charges, obviously 22 minus 30, multiplied by 89, which is around 712. So we know that we have roughly 8 months to save this customer, right? So we know that at 30th month, we would want to send some offers. Now those offers cannot be some random offer. It has to be very much relevant and targeted to the audience. That's why we again come back to the feature importance plot that we saw in the beginning. So as I had mentioned before, we will be focusing on those features which has less hazard ratio. In this case, it is payment by credit card, payment by bank transfer, whether the customer has one year contract or two year contract. If the customer has either one of these four features, there's a high probability that the customer will use your product for a very long period of time. Now instead of just talking, let's exactly see how each one of these features impact the survival chances. So again, going back to this customer, you can see the original subscription of this customer looked something like this. The customer had only subscribed for credit card payment and had no other subscription. So if you're sending some offer, make sure that the customer subscribes to this two year contract. So from this graph, you can clearly see that just by getting the customer subscribed to this two year contract, the survival chances like more than doubles. From 22, it is now as high as 55 month. So similarly for other features as well. And also you can see that if customer unsubscribes from this credit card due to some reason, the survival chances drops. So you don't want that to happen. So till now we saw how to pre-process the data, how we can build a model and how to send a targeted offer to our customer, right? So you are really happy with this. Now you do the entire analysis. Now you go ahead and present this to your boss. Now if your presentation looks something like this, all they are to think is what on the earth is going on, right? Because this is not at all comprehensive. So your presentation has to be such that everyone, no matter what their background is, should be able to identify what is going on. They should be able to tell, okay at this exact point of time, the customer is going to turn up, right? So that's when you start thinking, okay, fine. What if I build a web application out of it? Then you start thinking, okay, I need to start learning all this web framework such as Django or Flask, and then you start thinking about learning UI frameworks such as different UI frameworks, right? So what if I tell you, you don't have to learn any of those. You can build an entire end-to-end web application just using Python. So if you don't believe me, so there is this very cool package in Python called as Streamlit. It is the easiest and fastest way to build a web application using Python. And the best part is you don't even have to know any HTML and CSS for it. So if you don't believe me, you can see how simple writing the Streamlit code is. So all you have to do is import Streamlit as ST. And you have to keep embedding these Streamlit statements wherever you think it's necessary into your Python code itself. You don't have to create anything separately for this. For example, if you're doing a matplotlib, all you have to do is st.pyplot and you send the figure that you have built using matplotlib and that goes on to your web application. And if you think the plot needs some explanation, all you have to do is you have to do st.write and send any kind of description that you think should go on the website. It is as simple as that. And running the application is even more simple. All you have to do is Streamlit run and you have to send the Python file layer and there you go. You have a very nice web application running on your local server. Right? So in order to make this web application publicly available for anyone to use on the real-time basis, obviously you have to deploy this on cloud. In our case, we have deployed it on Heroku. So you can just follow these four simple steps to deploy any Python applications on Heroku. So for that, you just have to ensure these two files are present in your project. First is the requirement.txt, which has the names of all the packages that are required to run the Streamlit application. And you must have this proc file. So this proc file contains the command to run the Streamlit application. So in our case, it is just Streamlit run and the main Python file name. So as long as you have this, you are good to deploy your entire application on cloud. So this is what the architecture of today's demo is going to look like. We are going to feed in the CSV file as an input and we are going to build our model using all these super cool packages that we just spoke about. And then we'll be using Streamlit to build our web application. So let's directly jump into our demo. Yes. So yeah, this is the final web application that was built. And you can, from here, we'll be selecting our input file. So you can see how nicely it presents the entire information on the website. So this is the raw data that our website, that our database contains. And this is the pre-processed data. And then let's go ahead and build the model. So this is the different survival curve, how the survival chances varies with varying total charges. And this was entirely built using the Cox proportional hazard model. You can read more about that here. And then we can see how the model predicts. You can select any customer from this top term for which you want to predict the exact time when this customer might turn. So let's keep the default selection itself. So we can see that for this customer, at around 60th month, the customer is going to turn. And till around 35, 35th month, the survival chances of customer is completely high. So we can see here that at around 49th month, the survival chances of this customer drops by 50%. We can roughly see that from the graph as well. At around 49th month, it is dropping to around 50%. Now if you think that you cannot wait till the survival chances reduces to 50%, if you want to take action in the very beginning, then you just have to increase the criticality. Okay, just a second. We selected this data, we built the model. And this is the very nice feature, importance graph that we saw. And we are making up predictions. So if you increase the criticality of, you will see the exact time. In this case, we have increased it to 0.7. So here we will see the exact month when the customer is to 70%. Okay, it just takes a while to run. So yeah, it is coming slowly. Okay, at around 44th month, you can see the survival chances of customer has reduced to 70%. And finally you can see how changing each feature impacts the survival chances of your customer. Okay, there is some issue. But if you look at the model diagnostics, ultimately you need to ensure that whatever data, whatever model that you have built is good enough for any kind of prediction. And here you can see that the, our model is predicting pretty good for the lesser tenure period. And for the higher tenure period, our model is not really able to capture the entire essence of it, which is fine to some extent because you would want your model to perform really well when the tendency of the customer to churn is high, which is in the beginning of the, beginning stage of the customer lifecycle, right? So this is the entire application that I've built within just like a day. I'm sure you can do the great job with all your design skills and all. So if I can build this within a day, definitely you can do it too. So this is the entire summary of the talk. We pre-processed the data using pandas and if you have distributed data, go ahead and use tasks. We predicted the churn using left lines package and then we built a web application using streamlet and we finally deployed all our changes to the local. If you're really interested in playing around with this model, you can find the entire code in here. So these are the references if you are interested to learn more about this topic. And that's pretty much about all about it. Thank you so much for attending this talk. We are now open to taking questions. Thank you for awesome talk, Pramaja. And I appreciate that, you know, we kept it within time and also more from a topical perspective, a lot of people will appreciate that it is, it doesn't actually require a lot of code to go the last mile, right? Because that is what people, they do all the fancy stuff, but then they struggle at the end how to deploy, how to... Exactly. Exactly. We're open to questions. Yeah, so that was the whole idea of this talk to make sure that you not only build an amazing product, but you also present it in the most amazing way possible. And with Streamlet, it is definitely possible to do it without having to learn too many new tools. Right, so there have been some comments during the talk. Right, okay. So one is this looks similar to R Shiny. So do you have any experience with R Shiny? So this is like, so this is like literally, and of course, Shiny works only with R, so this is like one take on how it works, but it makes a lot more usage. Well, obviously it's hard to compare it with Shiny because Shiny has been around for a very long time. Streamlet just came, it's been about for a year, but it's gone the venture route, so there's been a lot more interest in terms of building this and then having more flexibility. But in the Python ecosystem, obviously this is the most popular one. I mean, this is the only one that provides the ease of use. There is a dash as well. So dash is predominantly for dashboarding. So if you think about these two things, if you do dash, dash is literally packaging plotly and then building dashboards, right? But what Streamlet provides us, access to APIs. So if you see this, what we have done is actually build the models and then provide the models as an API. We didn't have to explicitly go and build a flask or a Django app, as Padma just told. We didn't have to do specific stuff, okay, do you know how to do routing? Do you know how to do deployment? All those things have entirely abstracted away to some meaningful extent, right? So that makes it going to production that much more easier and simpler, especially for a data scientist who doesn't have so much of web skills to start with. Right. All right. So Sameer is asking, can you share the GitHub? Padma, can you throw up the resources once more? Yeah, so this is the link from where you can access the entire code. Right. Yeah, and I, for my part, I will get all the resources from Padma and Bhargava and I'll put them up on the Zoolog room and again, they'll all be on Twitter. We'll send out the mail, all of those good stuff. I think we are excellently on time and we also have the next speaker, Jennifer, in line. So Bhargava and Padma, thank you so much. Padma, thank you for an awesome talk. It was very clear. I think it was the pacing was perfect and it was good. Thank you. Thank you. Thanks a lot. I'm going to have you step down from the stage so we can move to the ads and then to... Thank you.