将批量数据发送到Azure ML端点

问题描述 投票:1回答:1

我有一个Azure ML端点,当我在json中提供数据时,该端点用于获得评分。

import requests
import json

# URL for the web service
scoring_uri = 'http://107a119d-9c23-4792-b5db-065e9d3af1e6.eastus.azurecontainer.io/score'  

# If the service is authenticated, set the key or token
key = '##########################'


data = {"data":
           [{'Associate_Gender': 'Male', 'Associate_Age': 20, 'Education': 'Under Graduate', 'Source_Hiring': 'Internal Movement', 'Count_of_Incoming_Calls_6_month': None, 'Count_of_Incoming_Calls_6_month_bucket': 'Greater than equal to 0 and less than 4', 'Internal_Quality_IQ_Score_Last_6_Months': '93%', 'Internal_Quality_IQ_Score_Last_6_Months_Bucket': 'Greater than 75%', 'Associate_Tenure_Floor_Bucket': 'Greater than 0 and less than 90', 'Current_Call_Repeat_Yes_No': False, 'Historical_CSAT_score': 'Greater than equal to 7 and less than 9', 'Customer_Age': 54, 'Customer_Age_Bucket': 'Greater than equal to 46', 'Network_Region_Originating_Call': 'East London', 'Length_of_Relationship_with_Customer': 266, 'Length_of_Relationship_with_Customer_bucket': 'Greater than 90', 'Call_Reason_Type_L1': 'Voice', 'Call_Reason_Type_L2': 'Prepaid', 'Call_Reason_Type_L3': 'Request for Reversal Provisioning', 'Number_of_VAS_services_active': 6, 'Customer_Category': 'Mercury', 'Customer_monthly_ARPU_GBP_Bucket': 'More than 30', 'Customer_Location': 'Houslow'}]
                        }
# Convert to JSON string
input_data = json.dumps(data)

# Set the content type
headers = {'Content-Type': 'application/json'}
# If authentication is enabled, set the authorization header
headers['Authorization'] = f'Bearer {key}'

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

如何从文件批量发送输入数据并获得输出。还是发送大量数据进行端点计分是不可行的?也欢迎对天蓝色评分的任何其他建议。

python azure machine-learning endpoint
1个回答
0
投票

假设您有一个名为json_data的文件夹,其中存储了所有json文件,然后您将打开这些文件并将其发布到端点,如下所示:

import requests
import json
import os
import glob

your_uri = 'https://jsonplaceholder.typicode.com/'
folder_path = './json_data'

for filename in glob.glob(os.path.join(folder_path, '*.json')):
    with open(filename, 'r') as f:
        json_input_data = json.load(f)
        resp = requests.post(your_uri, json_input_data)
        print(resp)

[要显示成功的http响应201,请在python文件的同一目录中创建一个文件夹,并将其命名为jsonplaceholder.typicode.com,然后在该文件夹中创建一些json文件,然后将一些数据粘贴到这些文件中,例如:

file1.json:

json_data

file2.json:

{
  "title": "some title name 1",
  "body": "some body content 1"
} 

您可以轻松地重写它,并使用自己的uri,键,标头等。

© www.soinside.com 2019 - 2024. All rights reserved.