# Demo program to score an input row via a REST call to a hosted model. # Step 1: Install httplib2 on the client that will make the REST call. # Step 2: Train the model by submitting a CSV file from the browser or # another client. Note the URL displayed for scoring. # Step 3: Run this program using the URL as the first command-line argument. # Example: # python model_two_sample_rest_client_python.py http://demo.snapanalytx.com/score/2/my_model/0ee502748553c35428582401de3e4fbab60d43e8 import httplib2 import sys import urllib def main(): url = sys.argv[1] # We will predict probabilty of buying a bike when a customer # has the following attributes. data = [('CustomerKey', 11000), ('NumberCarsOwned', 0), ('CommuteDistance', '1-2 Miles'), ('Region', 'Pacific')] # Send the attribute names as a CSV header. header = ','.join(x[0] for x in data) # Send the attribute values as a CSV row. row = ','.join(str(x[1]) for x in data) h = httplib2.Http('.cache') resp, content = h.request(url, 'POST', header + '\n' + row) print 'resp.status=%d' % resp.status print 'content=' + content if __name__ == '__main__': main()