k-NN 请求和响应格式 - Amazon SageMaker
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

k-NN 请求和响应格式

所有 Amazon SageMaker 内置算法遵循常见数据格式 - 推理中所述的常见输入推理格式。本主题包含 SageMaker k 最近邻算法的可用输出格式列表。

输入: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 请求格式

content-type: application/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 响应格式

content-type: application/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。

accept: application/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)