0
我想使用谷歌預測API。我已經訓練了我的模型,並通過網頁測試了一個預測,它效果很好。不過,我現在正在試圖使用Java API來預測了一系列的記錄,但我一直收到錯誤「無效的值:無法解析」谷歌預測API請求
com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid value for: Unable to parse '[feature1, feature2, feature3, feature4, feature5]'.",
"reason" : "invalid"
} ],
"message" : "Invalid value for: Unable to parse '[feature1, feature2, feature3, feature4, feature5]'."
對我來說,這似乎是JSON的創造者並沒有給周圍的特徵報價,但我下面儘可能接近樣品,他們不會更改或修改json工廠。這是證書和預測建築代碼。
private static GoogleCredential authorize() throws Exception {
GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
.setServiceAccountScopes(Collections.singleton(PredictionScopes.PREDICTION))
.setServiceAccountPrivateKeyFromP12File(new File("p12filefromdevconsole.p12"))
.build();
return credential;
}
...
Prediction prediction = new Prediction.Builder(
httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
...
private static Output predict(Prediction prediction, String... features) throws IOException {
Input input = new Input();
InputInput inputInput = new InputInput();
inputInput.setCsvInstance(Collections.<Object>singletonList(features));
input.setInput(inputInput);
Output output = prediction.trainedmodels().predict(PROJECT_ID, MODEL_ID, input).execute();
return output;
}
有什麼想法我做錯了?
其中預測API的版本,確實存在InputInput類?我無法找到任何版本的類來了。請幫忙..!! – 2015-03-24 07:09:43