prediction api

📢 Tatvic is now a global partner of Usercentrics, world’s leading consent management platform

prediction api

Last Updated:

Services:    

In this post, I am going to explain how can we build model for transactional product revenue prediction application 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 sets of your dataset which is  easy. Google Prediction API is developed with set of optimized Machine Learning Algorithms for model based prediction. Here is description on the base of the Prediction API v1.5

How to train data with Google Prediction API:

First, we require 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

  1. prediction.trainedmodels.insert – Can insert your dataset for training with this function.
  2. prediction.trainedmodels.get – Can get the training status of pre-inserted data model
  3. prediction.trainedmodels.analyze – Can provide the Analysis on the trained model
  4. prediction.trainedmodels.predict – Can make prediction

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.

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 by Predict method (prediction.trainedmodels.predict)

Test 1:

  1. xcartadd = 0
  2. xcartuniqadd = 0
  3. xcartaddtotalrs = 0
  4. xcartremove = 0
  5. xcardtremovetotal = 0
  6. xcardtremovetotalrs = 0
  7. xproductviews = 47
  8. xuniqprodview = 38
  9. xprodviewinrs = 5828

Actual  (Productrevenue) = 110.06

 Output
(Productrevenue) = 155.15717487938028

Test 2:

  1. xcartadd = 0
  2. xcartuniqadd = 0
  3. xcartaddtotalrs = 0
  4. xcartremove = 0
  5. xcardtremovetotal = 0
  6. xcardtremovetotalrs = 0
  7. xproductviews = 484
  8. xuniqprodview = 392
  9. xprodviewinrs = 445026

Actual (Productrevenue) = 803.81

 Output
(Productrevenue) = 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 dataset quality as well as prediction model as we already discussed in Product revenue prediction with R – part 2

Picture of tatvic

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.

Sign up for
our monthly newsletter

This field is for validation purposes and should be left unchanged.

Other Blog

Scroll to Top

Leverage Tatvic's comprehensive approach to 

Enquire Now

This field is for validation purposes and should be left unchanged.

Leverage Tatvic's comprehensive approach to 

Contact Us

Checkbox
This field is for validation purposes and should be left unchanged.