Predicting Churn with Automated Python Machine Learning

Nicholas Renotte · Intermediate ·📐 ML Fundamentals ·6y ago

Key Takeaways

The video demonstrates how to predict customer churn using automated Python machine learning pipelines with Order AI and Watson Studio, and deploy the model as a REST API. It covers building a machine learning pipeline, deploying the model, and making predictions on customer data.

Full Transcript

losing customers want to get a better handle on your customer relationships thanks for joining guys in today's video we're going to be taking a look at how to use machine learning to predict churn but specifically we're gonna be taking a look at how to do this using order AI and eventually how to export our code into a python jupiter notebook so let's take a little bit of a deeper look as to what we're going to be covering today so today we're going to be taking a look at how to use machine learning to predict churn we're then going to learn how to use that machine learning models to make predictions on new data and last but not least we're going to take that same machine learning model and we're going to export automatically into a jupiter notebook so we'll be able to take all the pipelines that we've trained and leverage that inside of our existing Python notebook now before we get too much further let's take a quick look at what churn is so churn occurs when a customer or an employee leaves a company so this is particularly important in business because it's a lot more expensive to attract a new customer than it is to retain an existing one so companies around the world try to minimize churn so that they can stop losing customers and effectively improve their bottom line now we can use a machine learning technique called binary classification to help us predict churn and that's exactly what we're going to be doing today so how exactly are we going to be doing this so we're going to be taking a CSV data set that has some historical data on customers that have churned we're then going to take that data set and import it into Watson studio so Watson Studios and all the one data science environments or anything that you might want to do as a data scientist you can do it within there we're then going to use that same CSV inside of Watson studio to build a machine learning model using order AI so or AI allows you to automate your Python machine learning pipelines and effectively gives you all of those pipelines to deploy as REST API s at the end once those models are finished training we're then going to export that model save it as a REST API but also going to take that same machine learning model and generate a Jupiter notebook with the underlying code for that machine learning model want to get into it let's do it already so every good data science project starts out with some data so let's go on ahead in grabs and data so in this case we're going to Kegel and there's a telco customer turn data set that we're going to be using I'll drop a link in the comments below if you want to grab that so don't fret now what we're going to do is just download that data set and you can see who downloaded it here and then we're going to extract that and find out because it's going to show up as a zip file so we can extract that and that's extracted now let's just rename that to data set - churn perfect now what we're going to do is we're going to step inside of Watson studio so what's in studio is where we're going to be doing the majority of our machine learning and training so if we go over to Watson studio if you haven't signed up for an account yet you can just go to Data Platform comm I was right Data Platform doc cloud ibm.com and you can sign up for an account that pretty easy now in this case we're going to create a project so a project sort of encapsulates all of your data science assets so we'll create an empty project and we'll call it telco churn photo AI so remember order air is going to be the tool that allows us to build an automated Python machine learning pipeline so eventually if you stick around to the end of the video we're going to export our machine learning pipeline into a jupiter notebook so we can then take that and really use it wherever we want so let's hit create and then so for homescreen within our project we can start adding different assets to our project so in this case we're going to go add project and the first thing that we're going to do is create an order AI experiment so from this sort of asset type page we can start adding the different things that we want to our project so here we're going to add order AI experiment and before we actually go into our experiment we need to associate a machine-learning service so this helps us perform our training and eventually deploy it to a REST API later on if we want to so here we're going to hit associate machine learning instance now if you don't have one you can just hit new create one and hit create down the bottom in this case we've already got one set up so I can just hit select from existing service choose that one and hit select then if I hit reload you can see my services now associated already now what we're going to do is name our experiment so here we'll call it churn prediction Python export because we're going to export it as a Python Jupiter notebook later on once our models finish training then we're going to hit create and then the next we're going to do is upload our data so remember we downloaded that Kegel data early on now we're just going to upload it into our project so we can start working with it so here we'll hit browse and go to our downloads and in this case app was called data set - churn so let's grab that and open that up now as soon as we select that order a is going to start pre processing our data so it's going to take a look at what columns we've got in there so in this particular data set we've actually got a column called churn and if we take go and take a look at that you can see that on the far right hand side we've actually got a column that says turn order it's titled churn and we've got no and yes so yes basically means that our customer has left the business no means that they're still with our business so they've been retained now what we want to do is train a machine learning model that allows us to predict whether or not the customer is likely to churn or not so effectively whether or not they're going to be yes or no now as soon as we upload our data set into order AI it's automatically going to pre process those columns as I was mentioning so what we can do is just scroll on down to our turn column select that and you can see automatically it's going to select the best type of machine learning for this particular task so in that case this is binary classification so if we wanted to change this we can go into experiment settings and change that if we wanted to it's fine for now it's going to work and it'll also choose our optimization metric so in this case it's going to train our model to optimize its model accuracy cool that's all done all we now need to do is just hit run experiment awesome so kicked off now what's going to happen as soon as we hit run experiment is ordere is going to start building a machine-learning pipeline now what it's actually going to do is it's going to go through all the same steps that you really should be doing in any data science project so if we hit swap view over here you can see that it's going to read in our data set it's going to split it into a training testing and holdout partition so that allows us to try to minimize the bias within our model it'll also read out our or read in our training data perform some pre-processing so it might fill in some missing values might perform some other pre-processing then it's also going to run through a bunch of different types of algorithms so in this case a lot of these models are Python packages so a lot of them come from scikit-learn so you've got extreme gradient boosting like GBM and a whole bunch of others now once it's started doing that it's actually going to run through each one of these pipelines here so you can see our first ones already finished training come to that in a second it's also going to perform some hyper parameter optimization to try to build a better model perform some feature engineering then perform some HPL again so effectively after it's finished this sort of stream you'll have one two three four pipelines then what it's also going to do is it's going to come down this stream and it's going to choose another algorithm and then do the same so you'll get another five six seven eight pipeline so all of you should have a leaderboard of eight machine learning pipelines now you can see that a few of them have finished training already and as you get better results or our eyes automatically going to select the best possible machine learning model for this particular task and you can see it's sad pipeline number two there because at the moment that's the one that's performing bets so if we go down to pipeline number two we can actually open that up and you can see our accuracy for pipeline number two is better than pipeline number one hence that's been chosen as the the best model at the moment the whole pipeline set hasn't finished so it's not going to choose the best potential model until that's completely done if we wanted to we could stop it there and just choose pipeline number two and deploy that one but we're going to let it run and finish all those models now you can also see here that you get a whole bunch of evaluation metrics so this allows you to delve a little bit deeper to see what's actually behind one of these pipelines now if you wanted to as well you can actually step into one of these pipelines and get some really cool information on what features are most important in your particular model so if I scroll all the way down here you can see that tenures Flags is probably one of our most important features likewise online security seems to be important so in terms of our telecommunications company that's trying to minimize churn they might take a look and go hey we need to take a look at tenure because we're losing a lot of customers that have either high or low tenure likewise they can interrogate whether or not they've got online security packages and internet service so quite quickly you can get an idea as to what features are important within your machine learning model or not now we're going to step back and wait for all our pipelines to finish training and then we're going to deploy our model to a jupiter notebook and take a look at that five minute early tell oh hi there we're back so now all of our machine learning model pipelines have finished training and you can see that pipeline number four is the best performing model so what we're going to do is we're going to deploy that model make some predictions and then we'll come back and we're going to convert that into its jupiter notebook so that we can play around with it in python so in this case what we need to do is just go to pipeline number four and hit save as model and so we're just gonna leave the naming hit save and so when we save this model we can then deploy it and make a bunch of predictions against it so we can then from this page so this is the model save page so you've got a bunch of information about the model we can then go to deployments hit add deployment and that we're just going to call this turn API and hit save so when we actually deploy this this actually creates a REST API so if you wanted to integrate this into other app or use the Python request library you could do that if you got JavaScript apps you could do that as well so I've seen this integrated into a whole bunch of different types of applications so the world is your oyster we're going to wait for this to finish deploying and then once that's deployed we can start making some predictions and then we'll go back create that drip in a notebook alrighty so our model is now deployed you can see the status is now showing up is ready so what we can do is step into that API and we can actually test it out by going to test all right and so the first thing that we're going to do is input the customer ID so if we scroll back let's just grab any customer ID so I'll grab this one grab this one I set in and then for gender the name type in what's that male senior citizen we'll put zero so pardon up so yes no it's just right yes no and so basically what we're doing now is we're scoring so we're entering in some data and we're pushing it against app deployed predictive model to try to get a prediction as to whether or not this particular type of customer will turn or not so in this case we'll put tenure we'll put it as a one phone service we'll set that as yes multiple lion will say yeah sure they've got multiple lines no internet no online security no online backup no device protection tech support yeah sure why not streaming TV yep streaming movies yep contract is month to month or one year so let's put month to month yep cool all right so paperless billing we're going to say yes and then yes and payment method is what does that need to be let's take a look at that column there will say electronic check monthly charges yeah 2995 total charges one hundred and twenty nine dollars now if we hit predict what's going to happen is all of this data is going to be sent to our deployed machine learning model and then ideally what we should get back is a prediction result so whether or not yes they have they're likely to turn on no they're likely to stay with our company so if we hit predict you can see this customer is going to stay with our company so it looks like we're all good now if we changed a bunch of stuff so say and the tenure is going to be ten years let's try predicting again okay so now they're going to turn so you can see by changing some of these factors we're gonna get different types of prediction results so you can see now that we've gone and deployed our machine learning model if we wanted to we can go to implementation and there's all the code there to deploy this as arrest it or to use it as a REST API in Java JavaScript Scala and just basic URL requests so you've got a whole bunch of stuff there to work with now what we want to do though is we want to export this as a Jupiter notebook so if we go back to our project and step back into our order AI experiment we can actually go back to our model and before we hit save as and went to our model in this case we're going to hit notebook instead then we want to select Auto AI Lib notebook and hit save so this is now going to generate a Jupiter notebook and we're actually going to be able to extract the Python code that sits beneath those order AI pipe lines cool so that's fine we'll leave it as that naming convention and hit create and so now no books is automatically going to start opening and then we'll be able to play around with it and see what's behind the scenes really perfect cool so this is our generator Python notebook so if we step through we can hit shift enter to run each cell and you can see we can see all the libraries that are behind these models we can step through it and if we wanted to we can go and change all of the information in this and tweak our model till our heart's content so we're not going to spend too much time looking through this we'll take a look at that in another video but if you have any questions be sure to drop a comment in the comments below that about wraps up this tutorial so let's quickly recap on what we did we built a machine learning model or rather 8 machine learning models using order AI we then deployed one machine learning model as a REST API and made some predictions so when we saw whether or not the customer was likely to turn on after we entered in all that data and last but not least we took that same machine learning model and we generated the underlying Python code using order a eyes notebook feature and that about wraps up today's tutorial now if you like this video be sure to give it a thumbs up and if you want to see any videos from me in the future be sure to subscribe thanks for tuning in guys peace

Original Description

Churn is a destroyer of businesses.... So how do you get ahead of it, you learn how to predict it. In this video you'll learn everything that's needed to get ahead of your churn rate. We'll go through: - How to build a machine learning pipeline to predict churn - Deploying the machine learning pipeline and making predictions - Generating a Python Jupyter Notebook from the automated pipeline Download the dataset: https://www.kaggle.com/blastchar/telco-customer-churn/data# Get Watson Studio: https://dataplatform.cloud.ibm.com/ Oh, and don't forget to connect with me! LinkedIn: https://www.linkedin.com/in/nicholasrenotte/ Facebook: https://www.facebook.com/nickrenotte/ GitHub: https://github.com/nicknochnack Happy coding! Nick P.s. Let me know how you go and drop a comment if you need a hand! Music by Lakey Inspired Better Days - https://www.youtube.com/watch?v=vtHGESuQ22s
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from Nicholas Renotte · Nicholas Renotte · 33 of 60

1 Face Detection - Build An Image Classifier with IBM Watson - Part 7
Face Detection - Build An Image Classifier with IBM Watson - Part 7
Nicholas Renotte
2 Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Food Image Classification - Build An Image Classifier with IBM Watson - Part 6
Nicholas Renotte
3 General Image Classification - Build An Image Classifier with IBM Watson - Part 5
General Image Classification - Build An Image Classifier with IBM Watson - Part 5
Nicholas Renotte
4 Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Installing Watson Developer Cloud - Build An Image Classifier with IBM Watson - Part 4
Nicholas Renotte
5 Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Generating Credentials - Build An Image Classifier with IBM Watson - Part 3
Nicholas Renotte
6 Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Creating A Service - Build An Image Classifier with IBM Watson - Part 2
Nicholas Renotte
7 Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Getting an IBMid - Build An Image Classifier with IBM Watson - Part 1
Nicholas Renotte
8 How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
How to Analyse Review Data - Part 2 - Python Yelp Sentiment Analysis
Nicholas Renotte
9 How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
How to Lemmatize Text - Part 4 - Python Yelp Sentiment Analysis
Nicholas Renotte
10 How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
How to Calculate Sentiment Using TextBlob - Part 5 - Python Yelp Sentiment Analysis
Nicholas Renotte
11 How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
How to Collect Business Reviews Using Python - Part 1 - Python Yelp Sentiment Analysis
Nicholas Renotte
12 How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
How to Clean Text Based Data for NLP - Part 3 - Python Yelp Sentiment Analysis
Nicholas Renotte
13 How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
How to Setup a IBM Watson Personality Insights Service - Part 1 - Watson Personality Insights
Nicholas Renotte
14 How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
How to Create a Customer Profile with IBM Watson - Part 2 - Watson Personality Insights
Nicholas Renotte
15 Visualising The Profile   Part 3   Watson Personality Insights
Visualising The Profile Part 3 Watson Personality Insights
Nicholas Renotte
16 How to Plot Personality Insights Features at Lightspeed - Part 4  - IBM Watson Personality Insights
How to Plot Personality Insights Features at Lightspeed - Part 4 - IBM Watson Personality Insights
Nicholas Renotte
17 Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Getting Started With IBM Watson Studio Machine Learning - Part 1 - Predicting Used Car Prices
Nicholas Renotte
18 Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Upload and Visualize Data In IBM Watson Studio - Part 2 - Predicting Used Car Prices
Nicholas Renotte
19 Clean Data and Feature Engineer in IBM Watson Studio - Part  3 - Predict Used Car Prices
Clean Data and Feature Engineer in IBM Watson Studio - Part 3 - Predict Used Car Prices
Nicholas Renotte
20 Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Using Watson Model Builder to Predict Car Prices - Part 4 - Predicting Used Car Prices
Nicholas Renotte
21 Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Deploy and Make Predictions With Watson Studio - Part 5 - Predicting Used Car Prices
Nicholas Renotte
22 Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Getting Started With IBM Watson Discovery - Part 1 - Stock News Crawler
Nicholas Renotte
23 How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
How to Run Advanced Queries with Watson Discovery - Part 5 - Stock News Crawler
Nicholas Renotte
24 How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
How to Run Search Queries with IBM Watson Discovery - Part 4 - Stock News Crawler
Nicholas Renotte
25 How to Understand the Watson Discovery Data Schema  - Part 3 - Stock News Crawler
How to Understand the Watson Discovery Data Schema - Part 3 - Stock News Crawler
Nicholas Renotte
26 How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
How to Build a Watson Discovery Web Crawler - Part 2 - Stock News Crawler
Nicholas Renotte
27 AI learns what to do next using Tensorflow and Python
AI learns what to do next using Tensorflow and Python
Nicholas Renotte
28 Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Chatbot Crash Course for Absolute Beginners - Full 20 Minute Tutorial
Nicholas Renotte
29 Shopify Customer Service Chatbot using Python Automation
Shopify Customer Service Chatbot using Python Automation
Nicholas Renotte
30 Building a Reddit Keyword Research Chatbot
Building a Reddit Keyword Research Chatbot
Nicholas Renotte
31 Chatbot App Tutorial with Javascript Node.js [Part 1]
Chatbot App Tutorial with Javascript Node.js [Part 1]
Nicholas Renotte
32 Javascript Chatbot From Scratch with React.Js [Part 2]
Javascript Chatbot From Scratch with React.Js [Part 2]
Nicholas Renotte
Predicting Churn with Automated Python Machine Learning
Predicting Churn with Automated Python Machine Learning
Nicholas Renotte
34 Sales Forecasting in Excel with Machine Learning and Python Automation
Sales Forecasting in Excel with Machine Learning and Python Automation
Nicholas Renotte
35 Automate Budgeting with Python and Planning Analytics
Automate Budgeting with Python and Planning Analytics
Nicholas Renotte
36 AI vs Machine Learning vs Deep Learning vs Data Science
AI vs Machine Learning vs Deep Learning vs Data Science
Nicholas Renotte
37 Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Optimizing Marketing Spend using Linear Programming || Marketing Opt PT.1
Nicholas Renotte
38 Solving Optimization Problems with Python Linear Programming
Solving Optimization Problems with Python Linear Programming
Nicholas Renotte
39 Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Loading Data into Planning Analytics with Python || Marketing Opt PT.2
Nicholas Renotte
40 Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Building Marketing Dashboards with Planning Analytics Workspace || Marketing Opt PT.3
Nicholas Renotte
41 Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Optimizing Resource Allocation with Docplex and Planning Analytics || Marketing Opt PT.4
Nicholas Renotte
42 Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Exploratory Data Analysis With Pandas || Python Machine Learning PT.1
Nicholas Renotte
43 Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Preparing Pandas Dataframes for Machine Learning || Python Machine Learning PT.2
Nicholas Renotte
44 Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Python Machine Learning with Scikit Learn - Regression || Python Machine Learning PT.3
Nicholas Renotte
45 Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Deploying Machine Learning Models with Watson Machine Learning || Python Machine Learning PT.4
Nicholas Renotte
46 Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Mind Blowing Machine Learning Apps with Node.JS and Watson Machine Learning || Python ML PT.5
Nicholas Renotte
47 Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Build FAST Machine Learning Apps with Javascript React.Js and Watson || Python ML PT.6
Nicholas Renotte
48 Analyzing Twitter Accounts with Python and Personality Insights
Analyzing Twitter Accounts with Python and Personality Insights
Nicholas Renotte
49 Converting Speech to Text in 10 Minutes with Python and Watson
Converting Speech to Text in 10 Minutes with Python and Watson
Nicholas Renotte
50 Build a Face Mask Detector in 20 Minutes with Watson and Python
Build a Face Mask Detector in 20 Minutes with Watson and Python
Nicholas Renotte
51 AI Text to Speech in 10 Minutes with Python and Watson TTS
AI Text to Speech in 10 Minutes with Python and Watson TTS
Nicholas Renotte
52 Pandas for Data Science in 20 Minutes | Python Crash Course
Pandas for Data Science in 20 Minutes | Python Crash Course
Nicholas Renotte
53 Language Translation and Identification in 10 Minutes with Python and Watson AI
Language Translation and Identification in 10 Minutes with Python and Watson AI
Nicholas Renotte
54 Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Analyse ANY Conversation in 10 Minutes with Python and Watson Tone Analyser
Nicholas Renotte
55 Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Deep Reinforcement Learning Tutorial for Python in 20 Minutes
Nicholas Renotte
56 NumPy for Beginners in 15 minutes | Python Crash Course
NumPy for Beginners in 15 minutes | Python Crash Course
Nicholas Renotte
57 Real Time Pose Estimation with Tensorflow.Js and Javascript
Real Time Pose Estimation with Tensorflow.Js and Javascript
Nicholas Renotte
58 Transcribe Video to Text with Python and Watson in 15 Minutes
Transcribe Video to Text with Python and Watson in 15 Minutes
Nicholas Renotte
59 Serverless Functions for TM1/Planning Analytics in 20 Minutes
Serverless Functions for TM1/Planning Analytics in 20 Minutes
Nicholas Renotte
60 Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Building a AI Budget Bot for Planning Analytics with Watson Assistant in 20 Minutes
Nicholas Renotte

This video teaches how to predict customer churn using automated Python machine learning pipelines and deploy the model as a REST API. It covers the entire process from building a machine learning pipeline to making predictions on customer data. By following this video, viewers can learn how to get ahead of their churn rate and improve their business.

Key Takeaways
  1. Download and extract a telco customer churn dataset from Kaggle
  2. Create a project in Watson Studio
  3. Add a project asset to the project
  4. Use Order AI to build an automated Python machine learning pipeline
  5. Export the model as a REST API and generate a Jupyter notebook with underlying code
  6. Create an Order AI experiment
  7. Associate a machine learning instance
  8. Name the experiment
  9. Upload data
  10. Preprocess data
💡 Automated Python machine learning pipelines can be used to predict customer churn and improve business outcomes.

Related AI Lessons

Up next
Is Python Dead in 2026?| Truth About Python in AI Era | 90 Days Roadmap @FameWorldEducationalHub
FAME WORLD EDUCATIONAL HUB
Watch →