<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/marketing-analytics-and-data-science/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html"> business-science.io - Articles</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Summary</h2>
<p>The data science community, Kaggle, recently announced the <a rel="nofollow" href="https://www.kaggle.com/c/ga-customer-revenue-prediction" target="_blank">Google Analytics Customer Revenue Prediction</a> competition. The competition uses data from the <a rel="nofollow" href="https://shop.googlemerchandisestore.com/" target="_blank">Google Merchandise store</a>, and the challenge is to create a model that will predict the total revenue per customer.</p>
<p>I’m using the Kaggle competition as an opportunity to show how data science can be used in digital marketing to answer a specific question, and take what is learned from the data and apply it to marketing strategies.</p>
<p>In my approach to the competition, I am using the <a rel="nofollow" href="https://www.business-science.io/bspf.html" target="_blank">Business Science Problem Framework</a> (BSPF), a methodology for applying data science to business problems.</p>
<p>The BSPF was developed by <a rel="nofollow" href="http://www.business-science.io/about" target="_blank">Matt Dancho</a> of Business Science. Business Science has an <a rel="nofollow" href="https://university.business-science.io/" target="_blank">online university</a> for learning data science on a pro level. I learned the BSPF methodology from their course, Data Science for Business with R.</p>
<h2>Contents</h2>
<h5>1. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#business-problem" target="_blank">The Business Problem</a></h5>
<h5>2. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#data-understanding" target="_blank">Data Understanding</a></h5>
<h5>3. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#data-preparation" target="_blank">Data Preparation</a></h5>
<h5>4. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#modeling" target="_blank">Modeling</a></h5>
<h5>5. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#evaluation" target="_blank">Evaluation</a></h5>
<h5>6. <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#impact" target="_blank">Impact – Business Benefit</a></h5>
<p></p>
<hr>
<h2>1. The Business Problem</h2>
<p>The competition outlines the problem:</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>The Google merchandise store wants to know which customers are generating the most revenue (customer value). Understanding customer value will allow the business to strategically dedicate resources to maximize their return on investment. More about this in the <a rel="nofollow" href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html#impact" target="_blank">Impact section</a>.</p>
<p><span><strong>The Goal: Predict the revenue of a customer</strong></span></p>
<p><i>Note: The article excludes some of my thought process and analysis for brevity and understanding for a non-technical.</i></p>
<h2>2. Data Understanding</h2>
<p>Exploratory data analysis (EDA) is an observational approach to understand the characteristics of the data. This step will provide insight into a data set, uncover the underlying structure and extract important variables.</p>
<p>EDA is a necessary step to understand the data before attempting to create a predictive model.</p>
<p>A big thanks to <a rel="nofollow" href="https://www.kaggle.com/erikbruin/google-analytics-eda-lightgbm-screenshots" target="_blank">Erik Brin for sharing his exploratory data analysis</a> on Kaggle. I share Erik’s EDA findings below. The full exploratory data analysis is quite long, therefore, I will focus on highlighting some of the important findings.</p>
<h3>2.1 Data Overview</h3>
<p>The data consists of approximately <strong>1.7 million records (observations)</strong> and is split between training and test datasets. The training data is used to train a machine learning model, while the test data is used to validate the accuracy of the model.</p>
<p>Each observation contains information, such as the number of times a user visited the store, the date/time of visit, the visitor’s country, etc. The data does not contain personal identifying information, with all persons identified by a visitor ID.</p>
<h3>2.2 Missing Data</h3>
<p>There are over <strong>900,000 observations in the training dataset</strong>, with each observation representing a store visit.</p>
<p><span><strong>The Takeaway:</strong></span> There are 14 variables in the training dataset containing missing values. Most of these variables are related to Google AdWords campaigns, we surmise the missing transaction revenue data means there was no transaction.</p>
<p>
<img border="0" src="https://i2.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-missing-data-2.png?w=456" data-recalc-dims="1">
</p>
<p></p>
<h3>2.3 Understanding Transaction Revenue</h3>
<p>Only 11,515 web sessions resulted in a transaction, which is 1.27% of the total observations.</p>
<p>Altogether, the store had 1.5 million dollars revenues in that year, with the range of revenues-per-transaction from $1 to approximately $23,000. Only 1.6% of the 11,515 transactions had revenues over $1,000.</p>
<p><span><strong>The Takeaway:</strong></span> Only a small percent of all the data resulted in a transaction, with almost all of the transactions resulting in less than $1000.</p>
<h3>2.4 Sessions and Revenues by Date</h3>
<p>The number of daily website sessions peaked in October and November 2016 but did not lead to higher daily revenues. In the revenues plot below, Daily Revenues vary between $0 and approximately $27,000 and that there is no revenues trend visible.</p>
<p>In addition, there are some <strong>outliers with high daily revenues</strong>. Notice the revenue spikes marked in yellow.</p>
<p>
<img border="0" src="https://i0.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-session-revenues-by-date-2.png?w=456" data-recalc-dims="1">
</p>
<p><span><strong>The Takeaway:</strong></span> I should consider revenue anomalies to accurately predict customer revenue.</p>
<h3>2.5 Sessions and Revenues by Workday</h3>
<p>Notice from the plot below there are fewer sessions and revenues on the weekend. A logical explanation seems that Google-branded merchandise is mostly bought by businesses who operate during the weekdays.</p>
<p>
<img border="0" src="https://i2.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-session-and-revenue-by-workday.png?w=456" data-recalc-dims="1">
</p>
<p><span><strong>The Takeaway:</strong></span> The weekend website sessions and revenue are lower than the weekdays.</p>
<h3>2.6 Sessions and Revenues by Month</h3>
<p>
<img border="0" src="https://i1.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-sessions-and-revenues-by-month.png?w=456" data-recalc-dims="1">
</p>
<p><span><strong>The Takeaway:</strong></span> Looking at the month patterns, April has a high ratio of revenues/sessions, and November has a low ratio of revenues/sessions. This is something to keep track of.</p>
<h3>2.7 Channel Grouping</h3>
<p>Channels define how people come to your website. The default channel groupings can be found <a rel="nofollow" href="https://support.google.com/analytics/answer/3297892" target="_blank">here</a>. These groups are mostly defined by the Medium, and some also by Source, Social Source Referral or Ad Distribution Network. From Google Analytics:</p>
<ul>
<li>Source: the origin of your traffic, such as a search engine (for example, Google) or a domain.</li>
<li>Medium: the general category of the source, for example, organic search (organic), cost-per-click paid search (CPC), web referral (referral).</li>
</ul>
<p>
<img border="0" src="https://i0.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-channel-grouping.png?w=456" data-recalc-dims="1">
</p>
<p><span><strong>The Takeaway:</strong></span> Organic Search and Social have a high number of sessions, with social producing very low revenue. Referral produces the most revenue, with a relatively small number of sessions.</p>
<h3>2.8 Pageviews; All Sessions</h3>
<p>A pageview indicates each time a visitor views a page on your website, regardless of how many hits are generated.</p>
<p>
<img border="0" src="https://i1.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/eda-pageviews-all-sessions-2.png?w=456" data-recalc-dims="1"><span>Most revenue relates to a low number of pageviews.</span>
</p>
<p><span><strong>The Takeaway:</strong></span> The distribution of pageviews is skewed. However, the second graph shows that most revenues came from a small number of sessions with a lot of pageviews! It may be that pageviews is a good factor for predicting revenue.</p>
<p></p>
<p></p>
<hr>
<h3>Solve Problems with Data Science Today!</h3>
<p><a rel="nofollow" href="https://university.business-science.io/p/hr201-using-machine-learning-h2o-lime-to-predict-employee-turnover/?product_id=635023&coupon_code=DS4B_15" target="_blank"><br>
<img alt="Data Science For Business With R Course" src="https://i2.wp.com/www.business-science.io/img/course_logo_full_DS4B_201_R.png?w=456" data-recalc-dims="1"><br>
</a></p>
<p><strong>To be efficient as a data scientist, you need to learn R.</strong> Take the course that has <strong>cut data science projects in half</strong> (see <a rel="nofollow" href="https://youtu.be/yw5CtGTzIw0" target="_blank">this testimonial</a> from a leading data science consultant) and has <strong>progressed data scientists more than anything they have tried before</strong>. Over 10-weeks you learn what it has taken data scientists 10-years to learn:</p>
<ul>
<li>Our systematic data science for business framework</li>
<li>R and H2O for Machine Learning</li>
<li>How to produce Return-On-Investment from data science</li>
<li>And much more.</li>
</ul>
<p>
<a rel="nofollow" href="https://university.business-science.io/p/hr201-using-machine-learning-h2o-lime-to-predict-employee-turnover/?product_id=635023&coupon_code=DS4B_15" target="_blank"><strong>Start Learning Today!</strong></a>
</p>
<p></p>
<hr>
<p></p>
<h2>3. Data Preparation</h2>
<p>With an understanding of the data, the next step is to prepare the data for modeling.</p>
<p>Data preparation is the process of <strong>formatting the data for people (communication) and machines (analyzing/modeling)</strong>, and perform correlation analysis to review and select the best features for modeling.</p>
<p>Much of this process is code-related, however, below is a correlation analysis that orders variables that are most likely to be good predictors.</p>
<p>
<img border="0" src="https://i1.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/correlation-1.png?w=456" data-recalc-dims="1"><span>Correlation analysis.</span>
</p>
<p>The correlation analysis is important because it gives insight into which variables have a good chance of helping the model. Above, pageviews and hits are two highly correlated (good for predicting) variables.</p>
<h3>3.1 Hypotheses – Important Variables</h3>
<p>Exploring and preparing the data provided a good understanding of the relationships between customer revenue and other variables in the data.</p>
<p>The following are my initial hypotheses that go into the model:</p>
<ul>
<li>
<p>Hypothesis 1: The time of day is an indicator of how much a person spends.<br>
To test this hypothesis, I created a new variable, hour of day. I extracted the hour of day from the store visitor’s session time.</p>
</li>
<li>
<p>Hypothesis 2: Visitor behavior is an indicator of how much a person spends.<br>
The existing data contains each visitor’s number of hits, pageviews, and visits. Along with the individual variables, I created a sum of these and combined them as visitor behavior.</p>
</li>
</ul>
<p></p>
<p>Before modeling, I performed an additional correlation analysis after adding the new variables from Hypothesis 1 and Hypothesis 2.</p>
<p>
<img border="0" src="https://i0.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/correlation-2.png?w=456" data-recalc-dims="1"><span>The new visitBehavior variable has a high correlation.</span>
</p>
<p>So far the variable visitBehavior from Hypothesis 2 looks correct. From the correlation ranking above, visitBehavior is a good variable for the model to predict customer revenue. The variable sessionHourOfDay from Hypothesis 1, however, is not a good predictor.</p>
<p></p>
<p><strong>Additional hypotheses to be tested (not in the current model):</strong></p>
<ul>
<li>New site visits is an indicator of how much a person spends.</li>
<li>A time-series approach will produce a more accurate model.</li>
<li>Address holidays and big sales days (such as Black Friday) to increase revenue prediction. The data does contain spikes in revenue. It would be interesting to see if there is an annual trend in revenue spikes and if there is a geographic trend with revenue spikes.</li>
</ul>
<h2>4. Modeling</h2>
<p>Deciding which variables that go into modeling will take into account the EDA takeaways, the correlation analysis, and my own hypotheses. I will be using the automated machine learning library H2O. H2O takes the prepared data and automatically creates several machine learning models. Once the models are created, they are ranked by performance and can be analyzed in detail.</p>
<p>Modeling with large datasets can use a lot of compute resources and take a long time to process. The H20 machine learning model was generated with a low runtime setting. Increasing this setting will help produce a more accurate model.</p>
<p>The top-performing generated machine learning model was a <a rel="nofollow" href="http://docs.h2o.ai/h2o/latest-stable/h2o-docs/data-science/drf.html" target="_blank">distributed random forest</a>.</p>
<h2>5. Evaluation</h2>
<p>With the baseline model now complete, I will submit the model to the Kaggle competition for results.</p>
<p>
<img border="0" src="https://i0.wp.com/www.business-science.io/assets/2018-10-26-marketing-analytics-data-science/kaggle-submission.png?w=456" data-recalc-dims="1">
</p>
<p>Now that the submission has been completed, I will continue to improve the model’s accuracy by testing additional hypotheses and evaluating model metrics.</p>
<h2>6. Impact – Business Benefit</h2>
<p>With the machine learning model complete, the Google Merchandise Store can identify customers that generate the most revenue.</p>
<p>Below are the business benefits to identifying high-value customers:</p>
<ul>
<li>Reduce customer churn with retention marketing for high-value customers</li>
<li>Identify likely high-value customers by analyzing existing high-value customer purchasing behavior</li>
<li>Predict revenue based on high-value customer purchasing history</li>
<li>Focus product development on high-value customer products</li>
</ul>
<p></p>
<hr>
<h3>You’ve made it all this way!</h3>
<p>Thank you for taking the time to read through this analysis. My purpose for making it is to show how digital marketing can benefit from data science analysis.</p>
<p>It’s not explicitly mentioned in the article, but <span><strong>what really makes this work is having a clearly defined question, sufficient data to answer the question, and a business process</strong></span> to work through the data science problem, such as <a rel="nofollow" href="https://www.business-science.io/bspf.html" target="_blank">Business Science Problem Framework</a>.</p>
<p>Although the exercise uses a large dataset, data science can be used to answer questions with fewer data as well.</p>
<p>
David Curry<br>
Founder, <a rel="nofollow" href="https://sureoptimize.com/" target="_blank">Sure Optimize</a> – Marketing Intelligence</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.business-science.io/business/2018/10/26/marketing-analytics-data-science.html"> business-science.io - Articles</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/oU5Sn2y8KTg" height="1"></a></div>