Azure ML-输入数据与输入端口架构不匹配

时间:2019-07-10 20:49:27

标签: python azure api jupyter

我想从Python-Jupyter Notebook调用Azure ML API。 Azure和Python之间匹配所有数据类型。但是仍然有一个错误...我该如何解决?

这是调用Azure ML的代码。

import pandas as pd
import numpy as np
import json
from urllib import request
import json

class Model:
    def __init__(self, url, api_key, colnames):
        self.url = url
        self.api_key = api_key
        self.colnames = colnames

    def predict_proba(self, values):
        if values.shape[0]==1:
            values = values.reshape(1, -1)
        data = {"Inputs": {"input1":{"ColumnNames": self.colnames, "Values": values.tolist()}},"GlobalParameters":  {}}
        body = str.encode(json.dumps(data))
        headers = {'Content-Type':'application/json', 'Authorization':('Bearer '+ self.api_key)}
        req = request.Request(self.url, body, headers)
        try:
            response = request.urlopen(req)
            result = response.read()
        except request.HTTPError as error:
            print("The request failed with status code: " + str(error.code))
            return np.array([])
        result_decoded = json.loads(result.decode())
        result = pd.DataFrame(result_decoded['Results']['output1']['value']['Values'], 
                              columns=result_decoded['Results']['output1']['value']['ColumnNames'])
        result['Scored Probabilities'] = result['Scored Probabilities'].astype(float)
        result['1-Scored Probabilities'] = result['Scored Probabilities'].apply(lambda x: 1-x)
        return np.array(result[['Scored Probabilities', '1-Scored Probabilities']])

输入和输出

#input
filepath = ""
input_df = pd.read_csv(filepath)
colnames = input_df.columns.tolist()
values = input_df.values
url = 'webservice_url'
api_key = 'api_key'

#output
model = Model(url,api_key, colnames)
prediction1 = model.predict_proba(values)

这是错误消息:

{
    'error': {
        'code': 'BadArgument', 
        'message': 'Invalid argument provided.', 
        'details': [{
            'code': 'InputMismatchError',
            'target': 'record_linkage_input',
            'message': 'Input data does not match input port schema.'
        }]
    }
}

0 个答案:

没有答案