Image for post
Image for post
Photo by SquareSpace

Customer Churn Prediction of a Music App using PySpark

Introduction

What is customer churn?

Why is the churn rate important?

Overview

Problem Statement

Step 1 — Understanding Data

root
|-- artist: string (nullable = true)
|-- auth: string (nullable = true)
|-- firstName: string (nullable = true)
|-- gender: string (nullable = true)
|-- itemInSession: long (nullable = true)
|-- lastName: string (nullable = true)
|-- length: double (nullable = true)
|-- level: string (nullable = true)
|-- location: string (nullable = true)
|-- method: string (nullable = true)
|-- page: string (nullable = true)
|-- registration: long (nullable = true)
|-- sessionId: long (nullable = true)
|-- song: string (nullable = true)
|-- status: long (nullable = true)
|-- ts: long (nullable = true)
|-- userAgent: string (nullable = true)
|-- userId: string (nullable = true)
>>> df.select('page').distinct().show(10)
+--------------------+
| page|
+--------------------+
| Cancel|
| Submit Downgrade|
| Thumbs Down|
| Home|
| Downgrade|
| Roll Advert|
| Logout|
| Save Settings|
|Cancellation Conf...|
| About|
+--------------------
>>> df.select('auth').distinct().show()+----------+
| auth|
+----------+
|Logged Out|
| Cancelled|
| Guest|
| Logged In|
+----------+
>>> df.select('level').distinct().show()+-----+
|level|
+-----+
| free|
| paid|
+-----+

Step — 2 Feature Engineering

Image for post
Image for post
Creating features for training
Image for post
Image for post
Features to train

Transforming Features

Image for post
Image for post
Image for post
Image for post
VectorAssembler & MinMaxScaler Implementation

Step — 3 Modeling

Splitting Data

Image for post
Image for post

Training

Image for post
Image for post
Logistic Regression Implementation

Step — 4 Evaluation

Prediction on the test set

Step — 5 Analysis

End Notes

Reference

Written by

Ex-Data Science Intern @ InterviewBit | Machine Learning | Deep Learning | Open Source Contributor

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store