AWS机器学习RealTimePredictor返回c#中的unknownooperationexception

本文关键字:中的 unknownooperationexception 返回 机器学习 RealTimePredictor AWS | 更新日期: 2023-09-27 18:05:06

使用Visual Studio和AWS . net V 3.0。

我正在尝试执行实时预测操作,并验证基本设置工作,我首先执行GetMLModel(),它工作并返回端点(在文档的某个地方提到使用该结果作为服务端点,但它与控制台中列出的相同)。状态为"READY",到目前为止一切顺利。

异常出现在"Prediction p = RTP.Predict(Data)"下面的行。数据包含一个字典,其中包含所有预测值。

Error: Error making request with Error Code unknownooperationexception and Http Status Code BadRequest。服务没有返回更多的错误信息。

public static APIResult GetRealTimePrediction(Dictionary<string, string> Data, string PayloadJSON = null) {
        AmazonMachineLearningConfig MLConfig = new AmazonMachineLearningConfig();
        MLConfig.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        MLConfig.Validate();
        AmazonMachineLearningClient MLClient = new AmazonMachineLearningClient("xxx", "xxx", MLConfig);
        GetMLModelResponse MLMOdelResp =  MLClient.GetMLModel("xxx"); // <-- WORKS
        MLConfig.ServiceURL = MLMOdelResp.EndpointInfo.EndpointUrl;
        Console.WriteLine(MLConfig.ServiceURL);
        MLConfig.Validate();
        Amazon.MachineLearning.Util.RealtimePredictor RTP = new Amazon.MachineLearning.Util.RealtimePredictor(MLClient, "xxx");
        Prediction P = RTP.Predict(Data); // <----------------EXCEPTION HERE
}

(显然用相关值替换xxx):)

AWS机器学习RealTimePredictor返回c#中的unknownooperationexception

结果是:

MLConfig.ServiceURL = MLMOdelResp.EndpointInfo.EndpointUrl;

表示MLConfig的大小写。要重置的RegionEndpoint。尽管文档表明可以从ServiceURL确定RegionEndpoint(我很确定我读过),但在RTP.Predict(Data)调用之前需要再次设置RegionEndpoint。

一旦我弄清楚了,我就能把代码减少到这样,以防其他人需要帮助。我想在配置中添加太多的信息并不是一件好事,就像AWS一样。. NET库似乎可以自己解决所有这些问题。

public static APIResult GetRealTimePrediction(Dictionary<string, string> Data, string PayloadJSON = null) {
        AmazonMachineLearningConfig MLConfig = new AmazonMachineLearningConfig();
        MLConfig.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        MLConfig.Validate(); // Just in case, not really needed
        AmazonMachineLearningClient MLClient = new AmazonMachineLearningClient("xxx", "xxx", MLConfig);
        Amazon.MachineLearning.Util.RealtimePredictor RTP = new Amazon.MachineLearning.Util.RealtimePredictor(MLClient, "xxx");
        Prediction P = RTP.Predict(Data);
}