Amazon Forecast 不再提供給新客戶。Amazon Forecast 的現有客戶可以繼續正常使用服務。進一步了解」
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
CreateForecast
搭配 AWS SDK 使用
下列程式碼範例示範如何使用 CreateForecast
。
- Java
-
- 適用於 Java 2.x 的 SDK
-
注意
GitHub 上提供更多範例。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.forecast.ForecastClient; import software.amazon.awssdk.services.forecast.model.CreateForecastRequest; import software.amazon.awssdk.services.forecast.model.CreateForecastResponse; import software.amazon.awssdk.services.forecast.model.ForecastException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class CreateForecast { public static void main(String[] args) { final String usage = """ Usage: <name> <predictorArn>\s Where: name - The name of the forecast.\s predictorArn - The arn of the predictor to use.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String name = args[0]; String predictorArn = args[1]; Region region = Region.US_WEST_2; ForecastClient forecast = ForecastClient.builder() .region(region) .build(); String forecastArn = createNewForecast(forecast, name, predictorArn); System.out.println("The ARN of the new forecast is " + forecastArn); forecast.close(); } public static String createNewForecast(ForecastClient forecast, String name, String predictorArn) { try { CreateForecastRequest forecastRequest = CreateForecastRequest.builder() .forecastName(name) .predictorArn(predictorArn) .build(); CreateForecastResponse response = forecast.createForecast(forecastRequest); return response.forecastArn(); } catch (ForecastException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; } }
-
如需 API 詳細資訊,請參閱 AWS SDK for Java 2.x API 參考中的 CreateForecast。
-
如需 AWS SDK 開發人員指南和程式碼範例的完整清單,請參閱 搭配 AWS SDK 使用預測。此主題也包含有關入門的資訊和舊版 SDK 的詳細資訊。
CreateDataset
DeleteDataset