3 Before you can run the prediction sample prediction.rb, you must load some csv
4 formatted data into Google Storage. You can do this by running setup.sh with a
5 bucket/object name of your choice. You must first create the bucket you want to
6 use. This can be done with the gsutil function or via the web UI (Storage
7 Access) in the Google APIs Console. i.e.:
9 # ./setup.sh BUCKET/OBJECT
10 Note you need gsutil in your path for this to work.
12 In the script, you must then modify the datafile string. This must correspond with the
13 bucket/object of your dataset (if you are using your own dataset). We have
14 provided a setup.sh which will upload some basic sample data. The section is
15 near the bottom of the script, under 'FILL IN DATAFILE'
19 We need to allow the application to use your API access. Go to APIs Console
20 https://code.google.com/apis/console, and select the project you want, go to API
21 Access, and create an OAuth2 client if you have not yet already. You should
22 generate a client ID and secret.
24 This example will run through the server-side example, where the application
25 gets authorization ahead of time, which is the normal use case for Prediction
26 API. You can also set it up so the user can grant access.
28 First, run the google-api script to generate access and refresh tokens. Ex.
30 # cd google-api-ruby-client
31 # ruby-1.9.2-p290 bin/google-api oauth-2-login --scope=https://www.googleapis.com/auth/prediction --client-id=NUMBER.apps.googleusercontent.com --client-secret=CLIENT_SECRET
33 Fill in your client-id and client-secret from the API Access page. You will
34 probably have to set a redirect URI in your client ID
35 (ex. http://localhost:12736/). You can do this by hitting 'Edit settings' in the
36 API Access / Client ID section, and adding it to Authorized Redirect URIs. Not
37 that this has to be exactly the same URI, http://localhost:12736 and
38 http://localhost:12736/ are not the same in this case.
40 This should pop up a browser window, where you grant access. This will then
41 generate a ~/.google-api.yaml file. You have two options here, you can either
42 copy the the information directly in your code, or you can store this as a file
43 and load it in the sample as a yaml. In this example we do the latter. NOTE: if
44 you are loading it as a yaml, ensure you rename/move the file, as the
45 ~/.google-api.yaml file can get overwritten. The script will work as is if you
46 move the .google-api.yaml file to the sample directory.
49 This sample currently does not cover some newer features of Prediction API such
50 as streaming training, hosted models or class weights. If there are any
51 questions or suggestions to improve the script please email us at
52 prediction-api-discuss@googlegroups.com.