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