Hello There!

Lorem ipsum dolor sit amet, consectetur adipiscing elit,

 About tatvic

Tatvic, a Google Premier Partner, empowers industry leaders with end-to-end Data & Marketing Analytics, leveraging Cloud, Analytics, Maps, and AI/ML for data-driven insights and future-proof digital growth.

Predict User’s Return Visit within a day part-2

Welcome to the second part of the series on predicting user’s revisit to the website. In my earlier blog Logistic Regression with R, I discussed what is logistic regression. In the first part of the series, we applied logistic regression to available data set. The problem statement there was whether a user will return in the next 24 hours or not. The model is built and till now it was showing us 88% accuracy in predicting user’s revisit.

In this post, I’d try to showcase ways to improve this accuracy and take it to the next level. This is more about technical optimization so  if you are a business reader you may want to skip and check how can you use this for your benefit. But, if you are techwiz or Data modeling guy like me, let’s get rolling.

As I have discussed in blog Improving Bounce Rate prediction Model for Google Analytics Data, the first step of the model improvement is variable selection and the second step is outlier detection (If you want to know more details of steps, refer mentioned blog). Let’s apply these steps one by one.

Variable selection

I have used stepwise backward selection method for variable selection. R code for the stepwise backward selection method is as below.

>Model_1 <- glm(revisit ~ DaySinceLastVisit + visitCount +f.medium +f.landingPagePath +f.exitPagepath+pageDepth, data=data ,family = binomial("logit"))
>library(MASS)
>stepAIC(Model_1, direction="backward")
Output
Start:  AIC=2119.37
revisit ~ DaySinceLastVisit + visitCount + f.medium + f.landingPagePath +  f.exitPagepath + pageDepth

                     Df Deviance    AIC
- f.exitPagepath    152   1732.4 1966.4
- f.landingPagePath  87   1751.0 2115.0
                    1581.4 2119.4
- pageDepth           1   1583.4 2119.4
- f.medium           11   1656.5 2172.5
- visitCount          1   1740.1 2276.1
- DaySinceLastVisit   1   1826.4 2362.4

Step:  AIC=1966.42
revisit ~ DaySinceLastVisit + visitCount + f.medium + f.landingPagePath + pageDepth

                     Df Deviance    AIC
                    1732.4 1966.4
- pageDepth           1   1738.9 1970.9
- f.landingPagePath 101   1987.5 2019.5
- f.medium           12   1821.2 2031.2
- visitCount          1   1929.3 2161.3
- DaySinceLastVisit   1   1978.4 2210.4

Before we understand the output, let me explain how the variables are selected in stepwise backward selection? In the stepwise backward selection method, AIC is used as the selection criterion. General rule is lower the AIC, best the model(i.e. For a group of variables, if AIC decrease by removing any variable(s) from group,then remaining variables are used in the model. This process continues until AIC stops decreasing). From the output, we can see that AIC is decreased and variable exitPageapath is excluded from the model. Now, we will create new model(Model_2 ) which does not include exitPageapath. R code for new model is as below.

>Model_2<-glm(revisit ~ DaySinceLastVisit + visitCount +f.medium +f.landingPagePath +pageDepth, data=data,family = binomial("logit"))

After generating the new model ,let’s check the accuracy of the new model and it is as below.

>predicted_revisit<- round(predict(Model_2,in_d,type="response"))
>confusion_matrix<- ftable(revisit, predicted_revisit)
>accuracy<- sum(diag(confusion_matrix))/2555*100
Output
86.57534

From the output, we can see that accuracy of the new model is decreased. This does not seem good to us. Variable selection method did not help us in improving the model. Let’s try second step for model improvement which is outlier detection.

Outlier detection

As we know that data set contains some unreliable observations which make model’s quality poor. We always need to detect outlier and remove them. For numerical variables, outliers can  be removed by observing the histogram of  frequency distribution of the values of each variable (Process is described in blog Improving Bounce Rate Prediction Model for Google Analytics Data). In our data set, there are three numerical variables named visitCount, daySinceLastVisit and pageDepth. I have generated new data set after removing outliers. Let’s create new model based on new data set and check the accuracy of the new model. R code for new model is as below.

>Model_3 <- glm(revisit ~ DaySinceLastVisit + visitCount +f.medium +f.landingPagePath +f.exitPagepath+pageDepth, data=data_outlier_removed ,family = binomial("logit"))

Now, we will check the accuracy of the new model and it is as below.

>predicted_revisit <- round(predict(Model_3,in_d,type="response"))
>confusion_matrix <- ftable(revisit, predicted_revisit)
>accuracy <- sum(diag(confusion_matrix))/2292*100
Output
98.42932

From the result, we can see that model has more accuracy than previous models (Model_1 and Model_2) and it is good for us. So, removing the outliers from the data set, the model got more improvement and prediction accuracy.  For now, we can conclude that through this model (Model_3), we can predict more accurately whether a user will return to website in next 24 hours. If you want to do exercise, Click here for R code and sample data set. In the next blog, we will discuss about logistic regression with Google Prediction API, check the accuracy of the Google Prediction API for our data set and try to predict for a user that will user return to website in next 24 hours?

Would you like to understand the value of predictive analysis when applied on web analytics data to help improve your understanding relationship between different variables? We think you may like to watch our Webinar - How to perform predictive analysis on your web analytics tool data. Watch the Replay now!

Regression with Google Prediction API

Prediction API

Welcome to the last part. In the previous blog, we have discussed about the model improvement and seen the summary of the improved model. In this post, I will discuss about regression with Google prediction API, compare it with our regression model and predict the bounce rate. When I used Google prediction API on the our data set, I found  following  result.

 

Let’s understand result first. Id of the model is “a1”, model type is “REGRESSSION”, number of instances are 8488(i.e. data set contains 8488 rows) and most important result is mean squared error which is 704.82. Here, there is no information about the coefficients of the model. Then, question arise how to evaluate model? Don’t worry, I will explain.

In the first part, I have explained about cost and if the cost is minimum then model is better. Cost of Google prediction API result is calculated as the square root of the mean square error and it is 26.55. However the cost of our improved model is termed as residual standard error and it is 24.83. If we compare these two costs , then we can say that R regression model is similar to the Google prediction API model.

After understanding the relationships between the bounce rate and time components, let’s predict the bounce rate through regression model. R provides predict() function to generate prediction. Suppose we have following observation for a webpage

  • avgServerResponseTime - 0.427189189
  • avgServerConnectionTime - 0.007081081
  • avgRedirectionTime - 0.318081081
  • avgPageDownloadTime - 0.416432432
  • avgDomainLookupTime - 0.033351351
  • avgPageLoadTime - 3.395026316

R code to generate prediction is as follow.

>insert_frame<- data.frame(avgServerResponseTime=0.427189189,avgServerConnectionTime=0.007081081,avgRedirectionTime=0.318081081,avgPageDownloadTime=0.416432432,avgDomainLookupTime=0.033351351,avgPageLoadTime=3.395026316)
>predict(Model_2,insert_frame,type='response')
Output
50.14

Let’s check the prediction of the above observation with Google Prediction API. This is shown below.

From the above result, we can see that prediction for observation is 48.39 and it is similar to the our prediction model.

Would you like to understand the value of predictive analysis when applied on web analytics data to help improve your understanding relationship between different variables? We think you may like to watch our Webinar - How to perform predictive analysis on your web analytics tool data. Watch the Replay now!

Visitor analysis using Google Analytics-Visitors Flow

Flow Visualization” in Google Analytics is a tool that allows you to analyze site insights graphically, and instantly understand how visitors flow across pages on your site. Currently GA offers two  types of visualizers: “Visitors Flow” and “Goal Flow” .The Visitor Flow Report allows you to graphically see the visitor’s navigation through your site. It shows exactly where the users came from, and which page they entered, progressed to, and left from. It is located under the grouping of Audience reports (the last option).
For this blog post,  my focus would be on how you can get better visitor insights using Visitors Flow. We will quickly traverse through three cases that can help you gain in-depth insight on your visitors.

How would Visitor flow report help me?

You can view the navigation from almost any dimension, such as country, source, medium, campaign and more. You can further slice it with advanced segments. Let’s take few cases that could help you know your visitors well.

1.    Analyze most popular path:
You can analyze the most popular path visitors take. Use this to plan and path your goal which will help you analyze how converting and non-converting users navigate your site. What after this? Well, this will help you making many decisions like:  Once you know the most popular path, you can decide the most strategic page (one amongst the most popular path’s pages) for particular advertisement or any content important to visitor’s conversion.

2.     Analyze the difference between paths of converting and non-converting visitors:
By analyzing the difference between the path of converting and non-converting visitors, you can gain many insights about what works best. For example, if the visitor A follows path (a->b->c->D) and converts (page D being the conversion page) and on the other hand visitor B follows the path (x->b->z->D) and does not convert , then there could be an issue with pages-x,z or may be the sequence is not working with them. But, this can be concluded if there are quite a few visitors that depict this behavior.

3.    Analyze your new visitors:
If your site experiences sudden boom in traffic you can analyze the properties of the new visitors, for example, country, and traffic source like campaign. You can also choose to include all visitors (instead of new visitors) to get the generalized idea of all the visitors.

Geographic Location specific Visitor Flow

4.    Analyze the properties of frequently converting visitors:

Language specific Visitor Flow

Looking at the country of visitors who convert (visits with transaction), say visitors from Brazil. If there are around 2k visitors who convert but, your site is only in US-English. Considering the number of people converting and the potential of further conversion rate from Brazil you may consider offering your site content in Portugal language as well. This will help you increase you conversions. Although, this is doable using custom reports, but the visual appeal and also the path followed by the visitors is an add on here which can help you gain better insights.
Campaign specific Visitor Flow

There is much more to this, you can apply various advanced segments, metrics and dimensions to narrow down your results and gain focused and helpful insights. But, to begin with, I hope this would be helpful.

Bot Icon
Bot Icon

Tatvic Bot

Explore About Tatvic and Services