In this post, I am going to explain how can we build the model for transactional product revenue prediction with Google Prediction API as we already discussed same stuff (Product revenue prediction with R)on R. With the help of Prediction API, we can build prediction model without any programming. Here we just have to focus on our dataset to make more accurate predictions. Google provides this service with Google Cloud Storage and Google Prediction API.
We can store our dataset at Google cloud storage and fire queries from Google prediction API for generating prediction on set of your datasets which is easy. Google Prediction API is developed with set of optimized Machine Learning Algorithms for model based prediction. Here, the description is on the base of the Prediction API v1.5
How to train data with Google Prediction API:
First, we require the minimum one number of project at our Google API console, enabled Google Prediction API and Google Cloud Storage service with that project. Our datasets have to meet certain format like
- There must no header for all column
- Predicted variable must be at first column
- There must not NA values in dataset which confuse Google Prediction server
Then we can upload our dataset to Google Cloud Storage Engine by creating bucket. After uploading dataset to Google Cloud Storage Engine, we have to query from Google Prediction API by Google API explorer. There are numbers of methods to Prediction API service to deal with the data like
- prediction.trainedmodels.insert – Can insert your dataset for training with this function.
- prediction.trainedmodels.get – Can get the training status of pre-inserted data model
- prediction.trainedmodels.analyze – Can provide the Analysis on the trained model
- prediction.trainedmodels.predict – Can make prediction
Here, we are making prediction for product revenue (yitemrevenue) on the base of the xcartadd, xcartuniqadd, xcartaddtotalrs, xcartremove, xcardtremovetotal, xcardtremovetotalrs, xproductviews, xuniqprodview and xprodviewinrs. Therfore, yitemrevenue is predicted variable and others are explanatory variables. As in previous blog, we have already developed model in R for same dataset. For doing same with Google Prediction API, We can start training of dataset with prediction.trainedmodels.insert with model unique id, data storage location, and type of model as parameters.
[You can use this dataset]Will give Response like:
It means request accepted by Google Prediction server and have started training. We can check the training status of model with the help of prediction.trainedmodels.get
Here is response of Get function of Prediction API:
Where it describes
Toatal numbers of instance = 4061
Type of model = Regression
Mean squared Error(MSE) = = 1606123.17
Here, this model summary will not provide intercept and variable coefficient like R. To make prediction with above model we can query with the followed data ( description ) by Predict method (prediction.trainedmodels.predict)
Test 1:
- xcartadd = 0
- xcartuniqadd = 0
- xcartaddtotalrs = 0
- xcartremove = 0
- xcardtremovetotal = 0
- xcardtremovetotalrs = 0
- xproductviews = 47
- xuniqprodview = 38
- xprodviewinrs = 5828
Actual (yitemrevenue) = 110.06
Output (yitemrevenue) = 155.15717487938028
Test 2:
- xcartadd = 0
- xcartuniqadd = 0
- xcartaddtotalrs = 0
- xcartremove = 0
- xcardtremovetotal = 0
- xcardtremovetotalrs = 0
- xproductviews = 484
- xuniqprodview = 392
- xprodviewinrs = 445026
Actual (yitemrevenue) = 803.81
Output (yitemrevenue) = 934
with R (after removing outliers + subsets of independent variable), we predicted 115.8346013 for test 1 and 955.153476 for test 2 on same dataset. Therefore, getting prediction with R and Google Prediction API are nearly same. When we are doing with prediction API we can improve prediction with improving dataset quality but another side in R, we can improve prediction accuracy by improving the dataset quality as well as the prediction model as we already discussed in Product revenue prediction with R – part 2.
Want us to help you implement or analyze the data for your visitors. Contact us

Vignesh Prajapati
Google Plus profile: Vignesh Prajapati

Latest posts by Vignesh Prajapati (see all)
- Google analytics data extraction in R - December 3, 2012
- Product revenue prediction with R – part 2 - October 8, 2012
- Product revenue prediction with R – part 3 - October 8, 2012