簡體   English   中英

Google Cloud Platform (GCP) JSON 上傳到 ML-Predict 時的預測文件錯誤

[英]Google Cloud Platform (GCP) JSON Prediction File error on Upload to ML-Predict

我在將測試數據上傳到 GCP 以進行預測時出錯。 我只是想將我的測試數據從 train_test_split 轉換為 json 文件,以運行我部署的 model 的 GCP 預測。

這是我的 dataframe 的樣子在此處輸入圖像描述

我的 X_test 都是 int 值。 這是我將此 dataframe 轉換為換行符分隔的 json 文件。

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_new, y, test_size=0.33, random_state=12, stratify = y) #stratify breaks up our split evenely

    import json

X_test_10 = X_test.head(10) #gets first 10 items for prediction
X_test_10.to_json('test.json') #converts file to json

#creates newline delimited json per google instructions
with open("test.json", "r") as read_file:
    data = json.load(read_file)
result = [json.dumps(record) for record in data]
with open('nd-proceesed.json', 'w') as obj:
    for i in result:
        obj.write(i+'\n')

#Uploads created json file to GCP model for prediction
!gcloud ai-platform predict --model voluntary_turnover --region us-east1 --json-instances nd-proceesed.json

Using endpoint [https://us-east1-ml.googleapis.com/]
{
  "error": "Prediction failed: Exception during sklearn prediction: could not convert string to float: 'response_count'"
}

錯誤消息“錯誤”:“預測失敗:sklearn 預測期間出現異常:無法將字符串轉換為浮點數:'response_count'”

我不確定為什么會收到此錯誤,因為我的數據未縮放並且我使用的是原始文件/數據。 我是否需要轉換為 numpy 數組然后上傳? 我不確定請幫忙!

我能夠使用下面的代碼解決這個問題。

import json
X_test_10 = X_test.head(200)#gets first 200 items for prediction
X_test_10_list = X_test_10.values.tolist()
data = {}
data['instances'] = X_test_10_list
    
with open('data_for_prediction.txt', 'w') as outfile:
    json.dump(data, outfile, indent = 2)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM