如何在 Azure ML Web 服务提供的 HttpResponseMessage 中获取预测分数?
How to get the Prediction Score in a HttpResponseMessage provided by a Azure ML Web Service?
所以我目前正在进行 Azure 机器学习实验。我能够创建一个模型并将其 post 作为 Web 服务。我还能够使用创建 Web 服务时生成的 API 文档中提供的 C# 示例 request/response 代码获得响应。
我的问题是,Web 服务提供的响应包含许多信息(一长串信息),包括预测分数,这是我的 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"]]}}}}
我只想要 "Values":[[...]] 内的值,在本例中为第 9 个索引或“1”。
您需要在 AML 实验中使用项目列。目前,您有一个连接到 Web 服务输出的模块。在 web service output
到 select 之前使用 project columns
模块只是您想要发送到我们输出的列。
此外,您可以取消选中评分模块的 "append columns" 属性,如下所示。这将只生成标签和概率列
所以我目前正在进行 Azure 机器学习实验。我能够创建一个模型并将其 post 作为 Web 服务。我还能够使用创建 Web 服务时生成的 API 文档中提供的 C# 示例 request/response 代码获得响应。
我的问题是,Web 服务提供的响应包含许多信息(一长串信息),包括预测分数,这是我的 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"]]}}}}
我只想要 "Values":[[...]] 内的值,在本例中为第 9 个索引或“1”。
您需要在 AML 实验中使用项目列。目前,您有一个连接到 Web 服务输出的模块。在 web service output
到 select 之前使用 project columns
模块只是您想要发送到我们输出的列。
此外,您可以取消选中评分模块的 "append columns" 属性,如下所示。这将只生成标签和概率列