Return Score from AutoML PredictResponse Object

Viewed 751

I'm trying to pull the score values out of my google automl PredictResponse Object. the object returned from the API looks as follows:

payload {
  classification {
    score: 0.989063024521
  }
  display_name: "No"
}
payload {
  classification {
    score: 0.0109369996935
  }
  display_name: "Yes"
}

I've gotten close using this:

result.payload[1]

Which returns:

classification {
  score: 0.0109369996935
}
display_name: "Yes"

But I still can't get to just the score for a yes or a no.

I've tried using simplejson, but the PredictResponse Object doesn't play nice with that either. Is there a function within the Object I can use to get to the Score for yes and the score for no? Appreciate the help!

4 Answers

This is the answer to your question:

result.payload[0].display_name

result.payload[1].classification.score

You may use the this code

d = {} for i in range(len(response.payload)): d[response.payload[i].display_name] = response.payload[i].classification.score

It will provide you a dictionary for all the categories (Yes and No in your case)
 predicted_data = []
 for i in range(len(response.payload)):
   predicted_data.append({
        "key": response.payload[i].display_name,
        "value": response.payload[i].classification.score
    })

key-value list of payload objects

Related