Google Analytics Customer Revenue Prediction — Dealing with Data
Tags: Python, Data Science, Kaggle, Machine Learning, Google Analytics

This blog is a part of a series about dealing with Data techniques for Google Analytics using machine learning

You can check out the rest of the articles below

As we have seen how to load our data now let's see how to deal with data and many ways to get more information from the data

Data Cleaning Missing Data Analysis Exploratory Data Analysis EDA Conclusions

1. Data Cleaning

Firstly as there are 60 different features let's remove the unwanted features.

We cannot say which features are not needed but if we have only one value for all the data its of no use

So we will remove the features having the same data for each visit

Above we removed the features having a count of unique values of a feature as 1

2. Missing Data Analysis

Let's see how much data is missing before we perform preprocessing and cleaning of data

In Train, the missing data is as follows.

Missing Data

As we can see above most of the data is missing and some features have missing data more than 90%

Now we will analyze each missing valued feature whether it is useful or not, if it is useful then we will analyze how to impute missing values else we will drop the feature.

missing data

SessionQualitydim and timesonsite have around 40% missing data.

We cannot impute with mean or median values for this because this varies from user to user. So we just impute “0” in these both features.

trafficSource.adwordsClickInfo.adNetworkType, trafficSource.adwordsClickInfo.gclId, trafficSource.adwordsClickInfo.slot, trafficSource.adwordsClickInfo.page

Above Features have more than 95% of missing data. We will drop all these features.

There is no source of even imputation as all these are unique ids for visits and slots for visits. So we drop these features.

trafficSource.keyword,trafficSource.referralPath

The above 2 features are categorical. We know that referral is important in any business. It helps us to focus on satisfied customers and increase potential customers.

We cannot impute these two features with any other categorical variable. Instead, we consider all null values into one category as others.

We can think like the users are not interested to give referrals and so on….

totals.transactions, totals.transactionrevenue

The above 2 features have around 95% + missing values but we know the 80–20 rule. Here totals.transactionrevenue is the target variable so we cannot drop this feature. We even cannot impute or change the target variable as it corrupts the data. So let's impute the features with 0 instead of null.

The above is the code for imputing 0’s in the 2 features.

Kaggle is considering transaction revenue as the target variable and not totalTransactionRevenue. So we will drop this totalTransactionRevenue feature. For more information click here.

3. Exploratory Data Analysis

Lets see what time tells us about the data

a) Target feature Analysis

In the above plot, we had users index on the x-axis and each user log transaction revenue value on the y-axis.

As we already discussed the 80/20 rule., by looking at this graph it was proved ., most of the transactions had generated zero revenue but only a few transactions had no-zero revenue.

b) day, month Analysis

Let's See how the time or period has a link with revenue.