2016-02-22 46 views
2

所以我目前正在使用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」。

回答

1

您需要在您的AML實驗中使用項目列。目前,您有一個連接到Web服務輸出的模塊。在web service output之前使用project columns模塊來選擇您想要發送到輸出的列。

+0

噢,這想法滑倒在我的腦海。謝謝!這解決了我的問題。 –

1

此外,您可以取消選中score模塊的「append columns」屬性,如下所示。那麼這隻會產生標籤和概率列

Score Module with only score labels and probabilities