Azure ML Studio环境中的Python自定义模型错误0085,在本地环境中正常工作 [英] Python Custom Model in Azure ML Studio Environment Error 0085, Works fine in Local Environment

查看:81
本文介绍了Azure ML Studio环境中的Python自定义模型错误0085,在本地环境中正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


Azure ML Studio环境在从自定义python模型中使用pickle文件时抛出以下错误。其中python本地模型,pickle文件适用于本地环境,但不适用于Azure ML Studio环境



错误0085:脚本评估期间发生以下错误,请查看输出日志以获取更多信息:---------- Python解释器启动错误消息----------执行函数时捕获异常:Traceback(最近调用最后一次) :
文件"C:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ 49,在azureml_main中返回DATA,model.predict_proba(DATA)文件"C:\ pyhome \lib \site-packages \sklearn \ mindmble \ forest.py",
line 540,in predict_proba n_jobs,_,_ = _partition_estimators(self.n_e stimators,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 )如果n_jobs<文件"C:\pyhome \ lib \site-packages \sklearn\utils__init __。py",
line 456,in _get_n_jobs 0:TypeError:unorderable类型:NoneType()< int()以非零退出代码1返回的进程----------来自Python解释器的错误消息结束----------



什么都丢失了?



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

 #脚本必须包含一个名为azureml_main的函数
#这是该模块的入口点。

#这里导入可以用于
导入pandas为pd
导入sys
导入pickle
来自sklearn.ensemble导入RandomForestClassifier
来自sklearn.preprocessing import LabelEncoder
import numpy as np
import pickle
import os

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

#执行逻辑到这里
#print('输入pandas。 DataFrame#1:\\\\\ n {0}'。format(DATA))

#如果一个zip文件连接到第三个输入端口已连接,
#它在".\Script Bundle"下解压缩。这个目录被添加到sys.path的
#。因此,如果你的zip文件包含一个Python文件
#mymodule.py你可以使用以下方法导入它:
#import mymodule

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

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

#返回值必须是pandas.DataFrame
的序列返回DATA,model.predict_proba(DATA)



python自定义模型需要在azure ml studio中使用,以便使用本地模型的相同输出来部署Web服务?


4月17日更新1:


Python版本2.7.11在本地和Azure ML Studio中是相同的,但发现, 

< g class =" gr_ gr_48 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id =" 48" id =" 48"> sklearn< / g>版本在本地不同[0.18.x ]和Azure ML Studio [0.15.x],其中train_test_split
不同于


## from sklearn.model_selection import train_test_split ##仅适用于0.18.x

import sklearn
$ b来自sklearn.cross_validation的$ b 导入train_test_split ##仅适用于0.15.x

print('sklearn version {0} .format(sklearn .__ version__))



1)现在,如何更新的<克类= QUOT; gr_ gr_46 GR-警报gr_spell gr_inline_cards gr_run_anim ContextualSpelling"数据-GR-ID =" 46" ID = QUOT; 46"> sklearn< / g取代;打包到Azure ML Studio中的最新版本?

或另一种方法是降级我的本地< g class =" gr_ gr_44 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace"数据-GR-ID =" 44" id =" 44"> sklearn< / g>,尝试一下,将试验这个
out。



2)另一项练习是,使用MDF [MulticlassDecisionForest]算法在Azure ML Studio中创建模型。

本地使用RFC [RandomForestClassifier]算法,但两个输出完全不同,不匹配?



以下代码位于本地环境中< g class =" gr_ gr_49 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling"数据-GR-ID =" 49" ID = QUOT; 49"> sklearn< / g取代;版本0.18.x使用RFC算法:

##本地环境中的随机森林分类器< g class =" gr_ gr_51 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling"数据-GR-ID =" 51" ID = QUOT; 51"> sklearn< / g取代;
版本0.18.x

来自< g class =" gr_ gr_53 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling"数据-GR-ID =" 53" id =" 53"> sklearn< / g> .ensemble import RandomForestClassifier



< span style ="white-space:pre"> ##随机森林分类器

rfc = RandomForestClassifier(n_estimators = 550,max_depth = 6,max_features = 30,random_state = 0) 

rfc.fit(X_train,y_train)

print(rfc)



##准确度测试

accuracy = rfc.score(X_test1,y_test1)

print(" Accuracy is {}" .format(accuracy))



3)使用较低版本的< g class =" gr_ gr_52 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling"使用Azure ML Studio Execute Python Script复制本地python代码。数据-GR-ID =" 52" ID = QUOT; 52"> sklearn< / g取代;
版本0.15.x


其中< g class =" gr_ gr_55 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep"数据-GR-ID =" 55" ID = QUOT; 55">导致< / g取代;同样的本地输出,除了极少数测试数据集
行?

现在,如何从Python脚本中训练模型作为未经训练的模型输入到Train Model组件?

或者在DataSet中编写pickle文件,并作为自定义模型使用?
$


非常感谢您的宝贵意见。


解决方案

嗨Mahadevan,


这看起来像是一个问题你的azureml_main()的返回值,请看一下

文档


azureml_main函数必须返回以Python序列打包的单个Pandas DataFrame,例如元组,列表,或NumPy数组。该序列的第一个元素返回到模块的第一个输出端口。模块
的第二个输出端口用于可视化,不需要返回值。



我认为你应该只返回结果。



------------------------------------------------- -------------------------------------------------- --------

如果您发现此信息有用,请将其命名为"有用"。投票。 

如果有帮助,请记得将回复标记为答案。



Azure ML Studio Environment throws the below error while consuming the pickle file from the custom python model. Where the python local model, pickle file works fine with the local environment, but not in Azure ML Studio Environment

Error 0085: The following error occurred during script evaluation, please view the output log for more information: ---------- Start of error message from Python interpreter ---------- Caught exception while executing function: Traceback (most recent call last): File "C:\server\invokepy.py", line 199, in batch odfs = mod.azureml_main(*idfs) File "C:\temp\b1cb10c870d842b9afcf8bb8037155a1.py", line 49, in azureml_main return DATA, model.predict_proba(DATA) File "C:\pyhome\lib\site-packages\sklearn\ensemble\forest.py", line 540, in predict_proba n_jobs, _, _ = _partition_estimators(self.n_estimators, self.n_jobs) File "C:\pyhome\lib\site-packages\sklearn\ensemble\base.py", line 101, in _partition_estimators n_jobs = min(_get_n_jobs(n_jobs), n_estimators) File "C:\pyhome\lib\site-packages\sklearn\utils__init__.py", line 456, in _get_n_jobs if n_jobs < 0: TypeError: unorderable types: NoneType() < int() Process returned with non-zero exit code 1 ---------- End of error message from Python interpreter ----------

Anything is missing?

Python Pickle file works fine with the local environment.

# 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)

The python custom model needs to be consumed in azure ml studio, to deploy web service, with the same outputs of the local model?

Update1 on April 17:

The Python Version 2.7.11 is same in local and Azure ML Studio but found out that, 
the <g class="gr_ gr_48 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="48" id="48">sklearn</g> version is different in local [0.18.x] and Azure ML Studio [0.15.x], where the train_test_split is different

##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) Now, how do update the <g class="gr_ gr_46 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="46" id="46">sklearn</g> package to the latest version in Azure ML Studio?
Or the other way is to degrade my local <g class="gr_ gr_44 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling ins-del multiReplace" data-gr-id="44" id="44">sklearn</g>, to try out, will experiment this out.

2) Another exercise did was, to create the model in Azure ML Studio using the MDF [MulticlassDecisionForest] Algorithm.
And the local was using RFC [RandomForestClassifier] algorithm, but both the outputs are entirely different, not matching?

Below code in the local environment with <g class="gr_ gr_49 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="49" id="49">sklearn</g> version 0.18.x using RFC algorithm:
## Random Forest Classifier in the local environment with <g class="gr_ gr_51 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="51" id="51">sklearn</g> version 0.18.x
from <g class="gr_ gr_53 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="53" id="53">sklearn</g>.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) Have reproduced the local python code with Azure ML Studio Execute Python Script with the lower version of <g class="gr_ gr_52 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" data-gr-id="52" id="52">sklearn</g> version 0.15.x

Which has <g class="gr_ gr_55 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar only-ins replaceWithoutSep" data-gr-id="55" id="55">resulted</g> the same outputs of local as well, except very few test data set rows?
Now, How to train the model from Python Script as Untrained model input to Train Model component?
Or to write the pickle file inside the DataSet, and to consume as Custom Model?

Your valuable inputs are much appreciated.

解决方案

Hi Mahadevan,

It looks like an issue in the return values of your azureml_main(), Please take a look at the documentation

The azureml_main function must return a single Pandas DataFrame packaged in a Python sequence such as a tuple, list, or NumPy array. The first element of this sequence is returned to the first output port of the module. The second output port of the module is used for visualizations and does not require a return value.

I think you should just return the result.

-----------------------------------------------------------------------------------------------------------
If you found this post helpful, please give it a "Helpful" vote. 
Please remember to mark the replies as answers if they help.


这篇关于Azure ML Studio环境中的Python自定义模型错误0085,在本地环境中正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆