本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
k-NN 请求和响应格式
所有 Amazon SageMaker AI 内置算法都遵循通用数据格式-推理中描述的通用输入推理格式。本主题包含 A SageMaker I k-nearest-neighbor 算法的可用输出格式列表。
输入:CSV 请求格式
content-type: text/csv
1.2,1.3,9.6,20.3
这接受 label_size
或编码参数。它采用值为 0 的 label_size
和 utf-8 编码。
输入:JSON 请求格式
content-type: application/json
{ "instances": [ {"data": {"features": {"values": [-3, -1, -4, 2]}}}, {"features": [3.0, 0.1, 0.04, 0.002]}] }
输入:JSONLINES 请求格式
content-type: application/jsonlines
{"features": [1.5, 16.0, 14.0, 23.0]} {"data": {"features": {"values": [1.5, 16.0, 14.0, 23.0]}}
输入:RECORDIO 请求格式
内容类型:应用程序/ x-recordio-protobuf
[ Record = { features = { 'values': { values: [-3, -1, -4, 2] # float32 } }, label = {} }, Record = { features = { 'values': { values: [3.0, 0.1, 0.04, 0.002] # float32 } }, label = {} }, ]
输出:JSON 响应格式
accept: application/json
{ "predictions": [ {"predicted_label": 0.0}, {"predicted_label": 2.0} ] }
输出:JSONLINES 响应格式
accept: application/jsonlines
{"predicted_label": 0.0} {"predicted_label": 2.0}
输出:详细 JSON 响应格式
在详细模式中,API 为搜索结果提供从最小到最大排序的距离向量,以及标签向量中的对应元素。在此示例中,k 设置为 3。
accept: application/json; verbose=true
{ "predictions": [ { "predicted_label": 0.0, "distances": [3.11792408, 3.89746071, 6.32548437], "labels": [0.0, 1.0, 0.0] }, { "predicted_label": 2.0, "distances": [1.08470316, 3.04917915, 5.25393973], "labels": [2.0, 2.0, 0.0] } ] }
输出:RECORDIO-PROTOBUF 响应格式
内容类型:应用程序/ x-recordio-protobuf
[ Record = { features = {}, label = { 'predicted_label': { values: [0.0] # float32 } } }, Record = { features = {}, label = { 'predicted_label': { values: [2.0] # float32 } } } ]
输出:详细 RECORDIO-PROTOBUF 响应格式
在详细模式中,API 为搜索结果提供从最小到最大排序的距离向量,以及标签向量中的对应元素。在此示例中,k 设置为 3。
接受:应用程序/x-recordio-protobuf;verbose=true
[ Record = { features = {}, label = { 'predicted_label': { values: [0.0] # float32 }, 'distances': { values: [3.11792408, 3.89746071, 6.32548437] # float32 }, 'labels': { values: [0.0, 1.0, 0.0] # float32 } } }, Record = { features = {}, label = { 'predicted_label': { values: [0.0] # float32 }, 'distances': { values: [1.08470316, 3.04917915, 5.25393973] # float32 }, 'labels': { values: [2.0, 2.0, 0.0] # float32 } } } ]
k-NN 算法的示例输出
对于 regressor 任务:
[06/08/2018 20:15:33 INFO 140026520049408] #test_score (algo-1) : ('mse', 0.013333333333333334)
对于 classifier 任务:
[06/08/2018 20:15:46 INFO 140285487171328] #test_score (algo-1) : ('accuracy', 0.98666666666666669)