blob: 1c4a78d916d0e94102a0c1dc1d5d51c75728962e [file] [log] [blame]
Joe Gregorio652898b2011-05-02 21:07:43 -04001# version: v1.2
2# scope: https://www.googleapis.com/auth/prediction
3# title: Simple command-line sample for the Google Prediction API
4# description: Command-line application that trains on some data. This sample does the same thing as the Hello Prediction! example.
5
6 # Name of Google Storage bucket/object that contains the training data
7 OBJECT_NAME = "apiclient-prediction-sample/prediction_models/languages"
8
9 # Start training on a data set
10 train = service.training()
11 start = train.insert(data=OBJECT_NAME, body={}).execute()
12
13 print 'Started training'
14 pprint.pprint(start)
15
16 import time
17 # Wait for the training to complete
18 while True:
19 status = train.get(data=OBJECT_NAME).execute()
20 pprint.pprint(status)
21 if 'RUNNING' != status['trainingStatus']:
22 break
23 print 'Waiting for training to complete.'
24 time.sleep(10)
25 print 'Training is complete'
26
27 # Now make a prediction using that training
28 body = {'input': {'csvInstance': ["mucho bueno"]}}
29 prediction = service.predict(body=body, data=OBJECT_NAME).execute()
30 print 'The prediction is:'
31 pprint.pprint(prediction)