bba1bae06421688eb9034bb99b973d8d6c0ca895
[arvados.git] / examples / prediction / README.md
1 APIs Console Project Setup
2 --------------------------
3 If you have not yet, you must set your APIs Console project to enable Prediction
4 API and Google Storage. Go to APIs Console https://code.google.com/apis/console/
5 and select the project you want to use. Next, go to Services, and enable both
6 Prediction API and Google Storage. You may also need to enable Billing (Billing)
7 in the left menu.
8
9
10 Data Setup
11 ----------
12 Before you can run the prediction sample prediction.rb, you must load some csv
13 formatted data into Google Storage. 
14
15 1 - You must first create the bucket you want to use. This can be done 
16 with the gsutil function or via the web UI (Storage Access) in the Google 
17 APIs Console. i.e. 
18 `$ gsutil mb gs://BUCKET`
19
20 OR
21
22 Go to APIs Console -> Storage Access (on left) and the Google Storage Manager,
23 and create your bucket there.
24
25 2 - We now load the data you want to use to Google Storage. We have supplied a
26 basic language identification dataset in the sample for testing.
27
28 `$ chmod 744 setup.sh`
29 `$ ./setup.sh BUCKET/OBJECT`
30 Note you need gsutil in your path for this to work.
31
32 If you have your own dataset, you can do this manually as well.
33 `$ gsutil cp your_dataset.csv gs://BUCKET/your_dataset.csv`
34
35
36 In the script, you must then modify the datafile string. This must correspond with the
37 bucket/object of your dataset (if you are using your own dataset). We have
38 provided a setup.sh which will upload some basic sample data. The section is
39 near the bottom of the script, under 'FILL IN DATAFILE'
40
41 API Setup
42 ---------
43 We need to allow the application to use your API access. Go to APIs Console
44 https://code.google.com/apis/console, and select the project you want, go to API
45 Access, and create an OAuth2 client if you have not yet already. You should
46 generate a client ID and secret. 
47
48 This example will run through the server-side example, where the application
49 gets authorization ahead of time, which is the normal use case for Prediction
50 API. You can also set it up so the user can grant access.
51
52 First, run the google-api script to generate access and refresh tokens. Ex.
53
54 `$ cd google-api-ruby-client`
55 `$ ruby bin/google-api oauth-2-login --scope=https://www.googleapis.com/auth/prediction --client-id=NUMBER.apps.googleusercontent.com --client-secret=CLIENT_SECRET`
56
57 Fill in your client-id and client-secret from the API Access page. You will
58 probably have to set a redirect URI in your client ID
59 (ex. http://localhost:12736/). You can do this by hitting 'Edit settings' in the
60 API Access / Client ID section, and adding it to Authorized Redirect URIs. Not
61 that this has to be exactly the same URI, http://localhost:12736 and
62 http://localhost:12736/ are not the same in this case.
63
64 This should pop up a browser window, where you grant access. This will then
65 generate a ~/.google-api.yaml file. You have two options here, you can either
66 copy the the information directly in your code, or you can store this as a file
67 and load it in the sample as a yaml. In this example we do the latter. NOTE: if
68 you are loading it as a yaml, ensure you rename/move the file, as the
69 ~/.google-api.yaml file can get overwritten. The script will work as is if you
70 move the .google-api.yaml file to the sample directory.
71
72
73 Usage
74 -----
75 At this, point, you should have 
76  - Enabled your APIs Console account
77  - Created a storage bucket, if required
78  - Uploaded some data to Google Storage
79  - Modified the script to point the 'datafile' variable to the BUCKET/OBJECT  name
80  - Modified the script to put your credentials in, either in the code or by
81    loading the generated .yaml file
82  
83 We can now run the service! 
84 `$ ruby prediction.rb`
85
86 This should start a service on `http://localhost:4567`. When you hit the service,
87 your ruby logs should show the Prediction API calls, and print the prediction
88 output in the debug. 
89
90 This sample currently does not cover some newer features of Prediction API such
91 as streaming training, hosted models or class weights. If there are any
92 questions or suggestions to improve the script please email us at
93 prediction-api-discuss@googlegroups.com.
94