k-NN 請求和回應格式 - Amazon SageMaker

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

k-NN 請求和回應格式

所有 Amazon SageMaker 內建演算法都遵循一般資料格式-推論中所述的通用輸入推論格式。本主題包含 SageMaker k-nearest-neighbor 演算法的可用輸出格式清單。

輸入:CSV 請求格式

content-type:text/csv

1.2,1.3,9.6,20.3

這會接受 label_size 或編碼參數。它假設 label_size 為 0 和 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}

輸出:VERBOSE 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 } } } ]

輸出:VERBOSE RECORDIO-PROTOBUF 回應格式

在詳細模式中,API 提供從最小到最大的距離向量排序搜尋結果,以及標籤向量中的對應元素。在這個範例中,k 設為 3。

接受:應用程序/x-recordio-protobuf; 字眼 = 真

[ 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 演算法的範例輸出

針對迴歸器任務:

[06/08/2018 20:15:33 INFO 140026520049408] #test_score (algo-1) : ('mse', 0.013333333333333334)

針對分類器任務:

[06/08/2018 20:15:46 INFO 140285487171328] #test_score (algo-1) : ('accuracy', 0.98666666666666669)