Google Analytics Customer Revenue Prediction
Tags: Handling Missing Values, Regression, Kaggle, Google Analytics, Finance

Welcome to the series about Google Analytics Customer Revenue Prediction using machine learning with python in a hands-on approach.

In this series, we’ll explore pretty much about the problem of Revenue Prediction of customers and solution for generating good revenue in future.

Here’s the set of articles in this series:

This intro guide is to understand the problem and basic idea on how to start with.

Introduction Real-world Problems Prerequisites Business Problem Data overview Understanding the data & Features Mapping to an ML Problem Reading Data

1. Introduction

What do you see in the below picture?

80–20

We can see that 20% is weighing much more than 80%. This is called the 80–20 Rule. Many Analysts say that the 80–20 Rule works everywhere. The 80–20 rule says that 20% has more impact than the other 80%.

This principle was observed in different fields like economics, epidemics, computing, sports, engineering, and many more, sometimes taking extreme values like 90%/10%, 95%/5%, or even 99%/1% but 80–20 performed better results than all.

So let's come back to the idea and look at where the 80–20 rule is used.

2. Real-world Sceanarios

A general example of the 80–20 rule is that 20% of the students have grades more than 80%. This is a case we can see everywhere. 20% of the leaders take care of 80% of the people. We know that leaders are very less in number, but they lead 80% of the people.

3. In the same way 20% of the customers generate 80% of the revenue. This is the case we use here.

3. Prerequisites

This post assumes you are familiar with basic Statistical and Machine learning Learning concepts like Dealing with Data, Pandas, Python basics, and Simple understanding on classification and regression .

4. Business Problem

The 80–20 Rule in Business states that 80% of the revenue is generated by 20% of the customers. So we need to find out the 20% of the potential customers so the marketing teams will focus more on them by Promotional Advertisements and attractive offers. So our goal is to find out the revenue generated by the 20% customers in future.

We were given customers past data like visits, transactions made by them in G-Store. We will analyze this and predict the customer's revenue in the future.

The 80/20 rule has proven true for many businesses–only a small percentage of customers produce most of the revenue. As such, marketing teams are challenged to make appropriate investments in promotional strategies.

5. Data overview

The data is taken from Kaggle competition. You can find the data from the below link

We need to download train_v2.csv,test_v2.csv

train_v2.csv — contains user transactions from August 1st, 2016 to April 30th, 2018.

test_v2.csv — contains user transactions from May 1st, 2018 to October 15th, 2018

We need to analyze train and test data and predict revenue for all the unique customers in test_v2.csv in the future (December 1st, 2018 through January 31st, 2019)

Each row in the Data set is a visit to the store. A customer can visit a store many times and can purchase only once or twice. Customers may visit many times and may not purchase anything as well.

6. Understanding the data & Features

The dataset has features as follows.

fullVisitorId- A unique id for each user or customer of the Google Merchandise Store.

channel grouping — The channel via which the user came to the Store.

date — The date on which the user visited the Store.

device — The specifications for the device used to access the Store.

geoNetwork — This section contains information about the geographic location of the user.

socialEngagementType — Engagement type, either “Socially Engaged” or “Not Socially Engaged”.

totals — This section contains aggregate values across the session.

trafficSource — This section contains information about the Traffic Source from which the session originated.

visitId — An id for this session. This is unique to the user. For a unique ID, you should use a combination of fullVisitorId and visitId.

visitNumber — value n in nth number of vists

visitStartTime — The timestamp of visitStartTime

hits — This row and nested fields are populated for any types of hits. Provides a record of all page visits.

customDimensions — This section contains any user-level or session-level custom dimensions that are set for a session. This is a repeated field and has an entry for each dimension that is set.

totals — This set of columns mostly includes high-level aggregate data

These are all the features present in the Data set given.

7. Mapping to an ML Problem

so here we are going to predict the revenue generated by the customer (in dollars) when he visits the store ., so we can pose this problem as a regression problem

Performance Metric

We are predicting the natural log of the sum of all transactions per user.

The submissions are calculated based on Metric RMSE.

Predicted is the predicted revenue for customer

Solution Idea

By going through a lot of resources and kaggle experts solutions the problem is solved as follows.

Firstly they will predict if the user will come to the store in the future or not using classification Model

Next, if the user comes to the store we will predict the revenue for that user

Solving a problem using both Classification & Regression is called as Hurdle Model

Hurdle Model

Hurdle model means Modelling the zero and non-zero data (classification) with one model

Then modeling the non-zero data for predicting the value

We will talk more about this in Feature Engineering

8. Reading Data

Reading train_v2.csv