machine-learningibm-cloudspss-modeler

Request to Machine Learning service on Bluemix using Python


I'm struggling in find a way to send data and have back the prediction of a SPSS model deployed on Bluemix Machine Learning service.

I make a lot of test using request library in Python or with curl command but I did not succeed.

I'm too new to Bluemix to understand the service documentation.

Any help,

Thanks


Solution

  • I managed to pass data in and receive the prediction with the code as follows:

    import requests, urllib3, json
    
    access_key= "INSERT_ACCESS_KEY_HERE"
    username = "INSERT_USERNAME_HERE"
    password = "INSERT_PASSWORD_HERE"
    headers = urllib3.util.make_headers(basic_auth='{}:{}'.format(username, password))
    
    payload_online= {  "tablename": "INSERT_TABLENAME_HERE",  "header": [INSERT_TABLE_HEADERS_HERE],"data": [[INSERT_DATA_TO_USE_FOR_THE_PREDICTION_HERE]]}
    
    url= 'https://ibm-watson-ml.mybluemix.net/pm/v1/score/INSERT_CONTEXTID_HERE?accesskey=INSERT_THE_ACCESS_KEY'
    
    header = {'Content-Type': 'application/json', 'Authorization': "INSERT_TOKEN_HERE"}
    
    
    response_online = requests.post(url, json=payload_online, headers=header)
    
    print(response_online.text)