Quickstart

This page shows you how to use Google Prediction API to train a model and answer queries. By using the provided training data and APIs Explorer, you'll quickly build a simple model that determines what language a phrase is written in.

Before you begin

  1. Sign in to your Google account.

    If you don't already have one, sign up for a new account.

  2. Select or create a Cloud Platform Console project.

    Go to the Projects page

  3. Enable billing for your project.

    Enable billing

  4. Enable the Prediction and Google Cloud Storage APIs for your project. Because you will use the APIs Explorer for this quickstart, you don't need to go to the Credentials page afterward.
  5. Download the sample training data file (language_id.txt). This file contains several text snippets and the language of each snippet (English, Spanish, or French) as CSV data.

Upload training data

  1. In the Google Cloud Platform Console:
    Open the Cloud Storage Browser
  2. Click Create bucket to create a new bucket.

    Create a bucket in the Cloud Storage Browser

  3. Enter a globally unique name in the Name field. The following name has been generated for you if you'd like to use it: quickstart-. Or, pick your own.

  4. Keeping the default values for the other fields, click Create.
  5. After the bucket is created, click Upload Files and upload language_id.txt.

    Upload the training file

Train the model

To train the model, call the prediction.trainedmodels.insert method, passing a unique name for this predictive model, and the location of the training data.

POST https://www.googleapis.com/prediction/v1.6/projects/[PROJECT_ID]/trainedmodels
{
 "id": "language-identifier",
 "storageDataLocation": "quickstart-1465256213/language_id.txt"
}

Use the button below to send this request using the APIs Explorer. You must replace the following values in the Explorer:

  • project: Your Cloud Platform Console project ID.
  • Request body: Update the value of storageDataLocation with your bucket name.

Try It!

A successful response looks like:

{
 "kind": "prediction#training",
 "id": "language-identifier",
 "selfLink": "https://www.googleapis.com/prediction/v1.6/projects/prediction-docs/trainedmodels/language-identifier",
 "storageDataLocation": "quickstart-1465256213/language_id.txt"
}

Confirm completion of training

Use the prediction.trainedmodels.get method to check the status of training, passing the ID of the predictive model.

GET https://www.googleapis.com/prediction/v1.6/projects/[PROJECT_ID]/trainedmodels/language-identifier

Use the button below to send this request using the APIs Explorer. You must replace the following values in the Explorer:

  • project: Your Cloud Platform Console project ID.

Try It!

In the response, examine the trainingStatus property to see if the status is RUNNING or DONE:

{
 "kind": "prediction#training",
 "id": "language-identifier",
 "selfLink": "https://www.googleapis.com/prediction/v1.6/projects/prediction-docs/trainedmodels/language-identifier",
 "created": "2016-06-07T22:51:13.702Z",
 "trainingComplete": "2016-06-07T22:51:32.468Z",
 "modelInfo": {
  "numberInstances": "406",
  "modelType": "classification",
  "numberLabels": "3",
  "classificationAccuracy": "0.99"
 },
 "trainingStatus": "DONE"
}

Send a query

After the training is complete, you can send queries to the service to be evaluated against the predictive model. To do so, call the prediction.trainedmodels.predict method, passing the name of the model and the query.

POST https://www.googleapis.com/prediction/v1.6/projects/prediction-docs/trainedmodels/language-identifier/predict

{
 "input": {
  "csvInstance": [
   "Sont des mots qui vont tres bien ensemble"
  ]
 }
}

Use the button below to send this request using the APIs Explorer. You must replace the following values in the Explorer:

  • project: Your Cloud Platform Console project ID.

Try It!

In the response, examine the outputLabel property to see what language the Google Prediction API thinks the string is in:

{
 "kind": "prediction#output",
 "id": "language-identifier",
 "selfLink": "https://www.googleapis.com/prediction/v1.6/projects/prediction-docs/trainedmodels/language-identifier/predict",
 "outputLabel": "French",
 "outputMulti": [
  {
   "label": "English",
   "score": "0.000000"
  },
  {
   "label": "French",
   "score": "1.000000"
  },
  {
   "label": "Spanish",
   "score": "0.000000"
  }
 ]
}

You can try sending queries in either of the other languages that the model was trained on (English and Spanish).

Clean up

To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:

  1. Delete your predictive model by calling the prediction.trainedmodels.delete method.

    Delete your model

  2. In the Google Cloud Platform Console, open the Cloud Storage Browser:
    Open the Cloud Storage Browser

  3. Click the checkbox next to the bucket you created and click Delete.

What's next

Send feedback about...

Prediction API Documentation