I here insert all the codes. So plz anyone help me to separate the values under the Column which named as "Scored Labels". e.g. either 1 or 0. Here basically I'm passing X axis, Y axis and Z axis values as request using urllib in Python. For that I'm getting response as bunch of list. Here I only need "Scored Labels" data only for other use.
Here is the sample request code
{
"Inputs": {
"input1": {
"ColumnNames": [
"X axis",
"Y axis",
"Z axis"
],
"Values": [
[
"0",
"0",
"0"
],
[
"0",
"0",
"0"
]
]
}
},
"GlobalParameters": {}
}
And here is the sample response
{
"Results": {
"output1": {
"type": "DataTable",
"value": {
"ColumnNames": [
"X axis",
"Y axis",
"Z axis",
"Scored Labels",
"Scored Probabilities"
],
"ColumnTypes": [
"Numeric",
"Numeric",
"Numeric",
"Numeric",
"Numeric"
],
"Values": [
[
"0",
"0",
"0",
"0",
"0"
],
[
"0",
"0",
"0",
"0",
"0"
]
]
}
}
}
}
All together sample code will be like this(This given in Request Response API Documentation for my Machine learning model web service)
import urllib2
# If you are using Python 3+, import urllib instead of urllib2
import json
data = {
"Inputs": {
"input1":
{
"ColumnNames": ["X axis", "Y axis", "Z axis"],
"Values": [ [ "0", "0", "0" ], [ "0", "0", "0" ], ]
}, },
"GlobalParameters": {
}
}
body = str.encode(json.dumps(data))
url = 'https://ussouthcentral.services.azureml.net/workspaces/b5eeedd29d564074b47a9c8ce5faa745/services/e6065c9017d0426196db3bbf0f78e9da/execute?api-version=2.0&details=true'
api_key = 'abc123' # Replace this with the API key for the web service
headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ api_key)}
req = urllib2.Request(url, body, headers)
try:
response = urllib2.urlopen(req)
# If you are using Python 3+, replace urllib2 with urllib.request in the above code:
# req = urllib.request.Request(url, body, headers)
# response = urllib.request.urlopen(req)
result = response.read()
print(result)
except urllib2.HTTPError, error:
print("The request failed with status code: " + str(error.code))
# Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
print(error.info())
print(json.loads(error.read()))
I'm getting output as
This get b'{"Results":{"output1":{"type":"table","value":{"ColumnNames":["X axis","Y axis","Z axis","Scored Labels","Scored Probabilities"],"ColumnTypes":["Double","Double","Double","Int32","Double"],"Values":[["0.202999","9.345999","-2.979","1","0.999358713626862"],["-0.15099999","9.378999","-2.8689999","0","1.45975587173552E-08"]]}}}}'
Process finished with exit code 0
For my this input -->. (I only need 4th parameter as either 0 or 1)
"Inputs": {
"input1":
{
"ColumnNames": ["X axis", "Y axis", "Z axis"],
"Values": [["0.202999", "9.345999", "-2.9790000"], ["-0.15099999", "9.378999", "-2.8689999"], ]
# "Values": [["0.202999", "9.345999", "-2.9790000"], ]
}, },
"GlobalParameters": {
}
Please help me solve this issue. Thanks in advance.
You could try the below snippet/
In the below snippet replace the x or store x with your output response.
import json
x = b'{"Results":{"output1":{"type":"table","value":{"ColumnNames":["X axis","Y axis","Z axis","Scored Labels","Scored Probabilities"],"ColumnTypes":["Double","Double","Double","Int32","Double"],"Values":[["0.202999","9.345999","-2.979","1","0.999358713626862"],["-0.15099999","9.378999","-2.8689999","0","1.45975587173552E-08"]]}}}}'
#print(x)
y= json.loads(x)
output = y["Results"]
for value in output["output1"]["value"]["Values"]:
print(value[3])