簡體   English   中英

Azure ML Studio 環境中的 Python 自定義模型錯誤 0085,在本地環境中工作正常

[英]Python Custom Model in Azure ML Studio Environment Error 0085, Works fine in Local Environment

Azure ML Studio 環境在使用自定義 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 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) 文件“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", line 456, in _get_n_jobs if n_jobs < 0: TypeError: unorderable types: NoneType() < int() Process returns with non-zero exit code 1 ----- ----- 來自 Python i 的錯誤消息結束翻譯 ----------

缺少什么嗎?

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 腳本訓練模型作為訓練模型組件的未訓練模型輸入? 或者將pickle文件寫入DataSet中,並作為自定義模型使用?

非常感謝您的寶貴意見。

這很可能是因為您用於序列化模型的pickle版本與 Azure ML Studio 用於反序列化的版本不同。 檢查Execute Python Script屬性以查看可用的 Anaconda/Python 版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM