所以我目前正在使用Azure機器學習實驗。我能夠創建一個模型並將其作爲Web服務發佈。我還能夠使用API文檔中提供的C#中的示例請求/響應代碼獲得響應,這些代碼是在創建Web服務時生成的。如何獲取由Azure ML Web服務提供的HttpResponseMessage中的預測分數?
我的問題是,Web服務提供的響應包含很多信息(一長串信息),包括Prediction Score,這是我需要的C#應用程序的唯一信息。唯一想到的就是使用字符串操作方法來提取我想要的信息。但我認爲有比這更好的方法。我是HTTP Request/Response的新手,請詳細說明相關答案和解釋。
這裏是我的代碼:
HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest);
if (response.IsSuccessStatusCode)
{
string result = await response.Content.ReadAsStringAsync();
Console.WriteLine("Result: {0}", result);
}
else
{
Console.WriteLine(string.Format("The request failed with status code: {0}", response.StatusCode));
// Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
Console.WriteLine(response.Headers.ToString());
string responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
這裏是響應消息:
{"Results":{"output1":{"type":"table","value":{"ColumnNames":["clump_thickness","size_uniformity","shape_uniformity","marginal_adhesion","epithelial_size","bare_nucleoli","bland_chromatin","normal_nucleoli","mitoses","Scored Labels","Scored Probabilities"],"ColumnTypes":["Int32","Int32","Int32","Int32","Int32","Nullable`1","Int32","Int32","Int32","Double","Double"],"Values":[["10","10","4","8","1","8","3","10","1","1","0.979712069034576"],["10","10","4","8","1","8","3","10","1","1","0.979712069034576"]]}}}}
我只想要 「值」 中的值:[[...]],在這種情況下,第9個指數或「1」。
噢,這想法滑倒在我的腦海。謝謝!這解決了我的問題。 –