首页 > 解决方案 > Azure ML Studio 环境中的 Python 自定义模型错误 0085,在本地环境中运行良好

问题描述

Azure ML Studio Environment 在使用自定义 python 模型中的 pickle 文件时引发以下错误。python 本地模型,pickle 文件在本地环境中可以正常工作,但在 Azure ML Studio 环境中不能正常工作

错误 0085:脚本评估期间发生以下错误,请查看输出日志以获取更多信息: ---------- Python 解释器的错误消息开始 ---------- Caught exception while执行函数: Traceback(最近一次调用):文件“C:\server\invokepy.py”,第 199 行,批量 odfs = mod.azureml_main(*idfs) 文件“C:\temp\b1cb10c870d842b9afcf8bb8037155a1.py”,行49、在 azureml_main 返回 DATA,model.predict_proba(DATA) 文件 "C:\pyhome\lib\site-packages\sklearn\ensemble\forest.py",第 540 行,在 predict_proba n_jobs, _, _ = _partition_estimators(self. n_estimators, self.n_jobs) 文件“C:\pyhome\lib\site-packages\sklearn\ensemble\base.py”,第 101 行,在 _partition_estimators n_jobs = min(_get_n_jobs(n_jobs), n_estimators) 文件“C:\pyhome\lib\site-packages\sklearn\utils__init__.py",第 456 行,在 _get_n_jobs 如果 n_jobs < 0: TypeError: unorderable types: NoneType() < int() Process returned with non-zero exit code 1 --- ------- Python 解释器的错误信息结束 ----------

有什么遗漏吗?

Python Pickle 文件适用于本地环境。

# 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
import sys
import pickle
from sklearn.ensemble import RandomForestClassifier
from sklearn.preprocessing import LabelEncoder
import numpy as np
import pickle
import os

def azureml_main(DATA = None, dataframe2 = None):

# Execution logic goes here
# print('Input pandas.DataFrame #1:\r\n\r\n{0}'.format(DATA))

# 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

sys.path.append('.\\Script Bundle\\MyLocalModel.zip')
sys.path.insert(0,".\Script Bundle")
model = pickle.load(open(".\Script Bundle\MyLocalModel.pkl", 'rb'))

#result = pd.DataFrame(model.predict_proba(dataframe1), columns=['p0','p1'])

# Return value must be of a sequence of pandas.DataFrame
return DATA, model.predict_proba(DATA)

python自定义模型需要在azure ml studio中使用,部署为web服务,与本地模型输出相同

4月17日更新1:

Python 版本 2.7.11 在本地和 Azure ML Studio 中是相同的,但发现本地 [0.18.x] 和 Azure ML Studio [0.15.x] 中的 sklearn 版本不同,其中 train_test_split 不同,如下代码:

##from sklearn.model_selection import train_test_split ## works only with 0.18.x
import sklearn
from sklearn.cross_validation import train_test_split ## works only with 0.15.x
print ('sklearn version {0}'.format(sklearn.__version__))

1) 现在,如何在 Azure ML Studio 中将 sklearn 包更新到最新版本?或者另一种方法是降级我的本地sklearn,尝试一下,将试验出来。

2) 另一个练习是使用 MDF [MulticlassDecisionForest] 算法在 Azure ML Studio 中创建模型。并且本地使用的是RFC [RandomForestClassifier]算法,但是两个输出完全不同,不匹配?

以下代码在 sklearn 版本 0.18.x 的本地环境中使用 RFC 算法: ## 随机森林分类器在本地环境中使用 sklearn 版本 0.18.x from sklearn.ensemble import RandomForestClassifier

## Random Forest Classifier
rfc = RandomForestClassifier(n_estimators = 550,max_depth = 6,max_features = 30,random_state = 0) 
rfc.fit(X_train,y_train)
print (rfc)

## Accuracy test
accuracy = rfc.score(X_test1,y_test1)
print ("Accuracy is {}".format(accuracy))

3) 使用 sklearn 版本 0.15.x 的较低版本的 Azure ML Studio 执行 Python 脚本复制了本地 python 代码,这也产生了相同的本地输出,除了很少的测试数据集行。现在,如何将 Python 脚本中的模型作为未训练模型输入训练模型组件?还是在 DataSet 中写入 pickle 文件,并作为自定义模型使用?

非常感谢您的宝贵意见。

标签: pythonmachine-learningazure-machine-learning-studioml-studiomlmodel

解决方案


这很可能是因为pickle您用于序列化模型的版本与 Azure ML Studio 用于反序列化的版本不同。检查Execute Python Script属性以查看可用的 Anaconda/Python 版本。


推荐阅读