AzureML Web服务错误

时间:2017-12-07 15:25:45

标签: python azure azure-machine-learning-studio

我尝试使用Python脚本在AzureML中实现随机林分类器。它在实验中运行良好但我在测试Web服务时遇到错误。

# The script MUST contain a function named azureml_main
# which is the entry point for this module.

# imports up here can be used to 
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score
from sklearn.metrics import confusion_matrix

# The entry point function can contain up to two input arguments:
#   Param<dataframe1>: a pandas.DataFrame
#   Param<dataframe2>: a pandas.DataFrame
def azureml_main(dataframe1 = None, dataframe2 = None):

    label_x = dataframe1[['NSP']]
    del dataframe1['NSP']

    label_y = dataframe2[['NSP']]
    del dataframe2['NSP']
    trained_model = random_forest_classifier(dataframe1, label_x)
    # print ("Trained model :: ", trained_model)
    predictions = trained_model.predict(dataframe2)


    # print ("Train Accuracy :: ", accuracy_score(label_x, trained_model.predict(dataframe1)))
    print ("Test Accuracy  :: ", accuracy_score(label_y, predictions))
    # print (" Confusion matrix ", confusion_matrix(dataframe2, predictions))
    cm = confusion_matrix(label_y, predictions)
    TP = cm[0][0]
    FP = cm[0][1]
    FN = cm[1][0]
    TN = cm[1][1]
    print("True Positive: ", TP, "False Positive: ", FP, "True Negative: ", TN, "False Negative: ",FN)
    # If a zip file is connected to the third input port is connected,
    # it is unzipped under ".\Script Bundle". This directory is added
    # to sys.path. Therefore, if your zip file contains a Python file
    # mymodule.py you can import it using:
    # import mymodule

    # Return value must be of a sequence of pandas.DataFrame
    return pd.DataFrame(predictions)

def random_forest_classifier(features, target):
    """
    To train the random forest classifier with features and target data
    :param features:
    :param target:
    :return: trained random forest classifier
    """
    clf = RandomForestClassifier()
    clf.fit(features, target)
    return clf

AzureML

当我通过输入值测试Web服务时,它会显示此错误。

  

85:错误0085:脚本评估期间发生以下错误,请查看输出日志以获取更多信息:---------- Python解释器启动错误消息-------- - 执行函数时捕获异常:Traceback(最近一次调用最后一次):文件&#34; \ server \ InvokePy.py&#34;,第120行,在executeScript outframe = mod.azureml_main(* inframes)文件&#34; \ temp-6305281036382248739.py&#34;,第52行,在azureml_main文件&#34; C:\ pyhome \ lib \ site-packages \ sklearn \ ensemble \ forest.py&#34;,第498行,预测proba = self .predict_proba(X)文件&#34; C:\ pyhome \ lib \ site-packages \ sklearn \ ensemble \ forest.py&#34;,第537行,在predict_proba中X = self._validate_X_predict(X)文件&#34; C:\ pyhome \ lib \ site-packages \ sklearn \ ensemble \ forest.py&#34;,第319行,在_validate_X_predict中返回self.estimators_ [0] ._ validate_X_predict(X,check_input = True)文件&#34; C: \ pyhome \ lib \ site-packages \ sklearn \ tree \ tree.py&#34;,第365行,在_validate_X_predict中X = check_array(X,dtype = DTYPE,acce pt_sparse =&#34; csr&#34;)文件&#34; C:\ pyhome \ lib \ site-packages \ sklearn \ utils \ validation.py&#34;,第407行,在check_array上下文中))ValueError:Found array 0个样本(形状=(0,21)),最小值为1。 ----------来自Python解释器的错误消息结束----------,错误代码:ModuleExecutionError,Http状态代码:400,时间戳:星期四,2017年12月7日15:24: 18 GMT

谁能告诉我错误在哪里?

0 个答案:

没有答案