In this project I analysed user interactions of a streaming service using Spark and created a machine learning model to predict user churn. The full description of the project can be found in a blog post on Medium.
The project was created with Python 3.7.16. Install the virtual environment using the requirements.txt of the project. The follwing packages are mainly used:
- pyspark
- pandas
- matplotlib
- seaborn
- numpy
- re, time, datetime
This is my capstone project of the Udactiy Nanodegree Data Scientist.
In this project I analysed user interactions of a streaming service using Spark. After understanding the business importance of churn, I explored a small subset of data to get a comprehension of the data and its quality. Then, I cleaned the data from missing values and created features which allow a machine learning model to find differences in the behaviour of users who stay with the service versus those who churn. With the prepared data I trained different classifiers and evaluated their performance with a suitable metric for imbalanced data. The result of the project is a Gradient-Boosted Tree Classifier which can identify users who will churn with high precision and high recall.
The
SparkBigData_ChurnDetection/
│
├── README.md
├── requirements.txt
├── Sparkify.ipynb --> jupyter notebook with code for small local data subset
├── Sparkify.html
├── Sparkify_aws.ipynb --> jupyter notebook with code for aws cluster
├── Sparkify_aws.html
├── img/ --> png's created in jupyter notebook
├── models/ --> trained ML models
├── data/ --> input data JSON file
The main findings of the code can be found at the post available here.
In this project I analyze user interactions of a streaming service using Spark. After understanding the business importance of churn, I explore a small subset of data to get a comprehension of the data and its quality. Then, I clean the data from missing values and create features which allow a machine learning model to find differences in the behaviour of users who stay with the service versus those who churn. With the prepared data I train different classifiers and evaluated their performance with a suitable metric for imbalanced data. The result of the project is a Gradient-Boosted Tree Classifier which can identify users who will churn with high precision and high recall:
+--------------+---------------+ |Metric | Gradient Boost| +--------------+---------------+ |F1-score | 71% | |Area under ROC| 58% | +--------------+---------------+
I give credit to Udacity for the data (user_log).
Feel free to use my code as you please:
Copyright 2020 Leopold Walther
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.