简体   繁体   English

Azure ML 时间序列预测 model 的数据输入格式(调用服务)部署为 web 服务(Python)

[英]Data input format (call the service) for Azure ML time series forecast model deployed as a web service (Python)

Sorry in advance for the lengthy question as I wanted to explain it as detailed as possible.提前抱歉这个冗长的问题,因为我想尽可能详细地解释它。 I used the Azure AutoML to train a model and deployed it as a web service.我使用 Azure AutoML 来训练 model 并将其部署为 web 服务。 Now I can access (call) it over the REST endpoint.现在我可以通过 REST 端点访问(调用)它。

I have the following data types for attributes: date (timestamp), number, number, number, number, integer.我有以下属性数据类型:日期(时间戳)、数字、数字、数字、数字、integer。 I trained the model with the following parametres:我使用以下参数训练了 model:

  • Timestaps interval: 15 min时间戳间隔:15 分钟
  • Forecast Horizon: 4 (I need the forecast every hour for the next hour) Forecast Horizon:4(我需要每小时预测下一小时)
  • Target rolling window size: 96 (the forecast must ba based on the last 24 hours of data)目标滚动 window 大小:96(预测必须基于最近24小时的数据)

As I understand, based on the above, I have to provide last 4 entries to the model for a correct prediction.据我了解,基于上述内容,我必须向 model 提供最后 4 个条目以进行正确预测。 Otherwise, it will consider a time gap.否则,将考虑时间间隔。 Am I right?我对吗? In this case, how I could input 4 instances at a time for a single prediction?在这种情况下,我如何一次输入 4 个实例来进行单个预测? The following example is wrong as it asks for 4 predictions for each instance:以下示例是错误的,因为它要求为每个实例提供 4 个预测:

    import requests
    import json

    # URL for the web service
    scoring_uri = 'http://xxxxx-xxxxxxx-xxxxxx-xxxxxxx.xxxxx.azurecontainer.io/score'

    data = {"data":
            [
                [
                    2020-10-04 19:30:00,1.29281,1.29334,1.29334,1.29334,1
                ],
                [
                    2020-10-04 19:45:00,1.29334,1.29294,1.29294,1.29294,1
                ],
                [
                    2020-10-04 21:00:00,1.29294,1.29217,1.29334,1.29163,34
                ],
                [
                    2020-10-04 21:15:00,1.29217,1.29257,1.29301,1.29115,195]
            ]
            }
    # Convert to JSON string
    input_data = json.dumps(data)

    # Set the content type
    headers = {'Content-Type': 'application/json'}

    # Make the request and display the response
    resp = requests.post(scoring_uri, input_data, headers=headers)
    print(resp.text)

The above code is based on the provided Microsoft example https://docs.microsoft.com/en-us/azure/machine-learning/how-to-consume-web-service?tabs=python#call-the-service-python .上述代码基于提供的 Microsoft 示例https://docs.microsoft.com/en-us/azure/machine-learning/how-to-consume-web-service?tabs=python#call-the-service-蟒蛇

I am unable to replicate the provided example with my data.我无法用我的数据复制提供的示例。 I have an error "SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers" pointing to the date.我有一个错误“语法错误:十进制 integer 文字中的前导零是不允许的;对八进制整数使用 0o 前缀”指向日期。 I assume, I need to specify the data type but could not find how.我假设,我需要指定数据类型但找不到如何。

I very appreciate any help or direction.我非常感谢任何帮助或指导。 Thank you.谢谢你。

This issue was solved by AlphaLu-0572's answer , add it as the answer to close the question: AlphaLu-0572 的回答解决了这个问题,将其添加为关闭问题的答案:

The service takes data in form of deserialized pandas data frame.该服务以反序列化的 pandas 数据帧的形式获取数据。 In the example below, it will look like:在下面的示例中,它将如下所示:

import json

X_test = pd.DataFrame([

 ['2020-10-04 19:30:00', 1.29281, 1.29334, 1.29334, 1.29334, 1],
 ['2020-10-04 19:45:00', 1.29334, 1.29294, 1.29294, 1.29294, 1],
 ['2020-10-04 21:00:00', 1.29294, 1.29217, 1.29334, 1.29163, 34],
 ['2020-10-04 21:15:00', 1.29217, 1.29257, 1.29301, 1.29115, 195]],
 columns=['date', 'number_1', 'number_2', 'number_3', 'number_4', 'integer']

)

test_sample = json.dumps({'data': X_test.to_dict(orient='records')})

test_sample

Which will result in JSON string as:这将导致 JSON 字符串为:

{"data": [{"date": "2020-10-04 19:30:00", "number_1": 1.29281, "number_2": 1.29334, "number_3": 1.29334, "number_4": 1.29334, "integer": 1}, {"date": "2020-10-04 19:45:00", "number_1": 1.29334, "number_2": 1.29294, "number_3": 1.29294, "number_4": 1.29294, "integer": 1}, {"date": "2020-10-04 21:00:00", "number_1": 1.29294, "number_2": 1.29217, "number_3": 1.29334, "number_4": 1.29163, "integer": 34}, {"date": "2020-10-04 21:15:00", "number_1": 1.29217, "number_2": 1.29257, "number_3": 1.29301, "number_4": 1.29115, "integer": 195}]}

Please rename the columns to the corresponding columns from the training data set.请将列重命名为训练数据集中的相应列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure ML 时间序列 model 数据输入期间的推理错误(python) - Azure ML time series model inference error during data input (python) Azure ML Web服务+用于查询熊猫数据框的Python - Azure ML Web Service + Python for Querying Pandas Data Frame 在 python 中使用 ARIMA model 预测时间序列数据的任何方法? - Any way to forecast time series data using ARIMA model in python? “输入数据”作为列表而不是Azure ML Web服务中的列表列表 - 'Enter Data' as list instead of list of lists in Azure ML Web Service 使用 Python 预测时间序列? - Forecast of a time series with Python? Python时间序列ARIMA预测 - Python Time Series ARIMA Forecast 如何从Azure ML中的python脚本获取Web服务的输出 - How to get output from a web service from a python script in Azure ML 使用python存储预测时间序列数据的方法 - Approach to storing forecast time series data using python 在 python 中,如何在 django 或flask 等休息服务中只加载一次 ML 模型? - in python , How to load just one time a ML model in a rest service like django or flask? 使用 Prophet 预测 Python 中的多个时间序列 - Using Prophet to forecast multiple time series in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM