【发布时间】:2020-03-29 06:27:17
【问题描述】:
我有一个 sklearn k-means 模型。我正在训练模型并将其保存在 pickle 文件中,以便稍后使用 azure ml 库进行部署。我正在训练的模型使用名为 MultiColumnLabelEncoder 的自定义特征编码器。 管道模型定义如下:
# Pipeline
kmeans = KMeans(n_clusters=3, random_state=0)
pipe = Pipeline([
("encoder", MultiColumnLabelEncoder()),
('k-means', kmeans),
])
#Training the pipeline
model = pipe.fit(visitors_df)
prediction = model.predict(visitors_df)
#save the model in pickle/joblib format
filename = 'k_means_model.pkl'
joblib.dump(model, filename)
模型保存工作正常。部署步骤与此链接中的步骤相同:
但是部署总是失败并出现此错误:
File "/var/azureml-server/create_app.py", line 3, in <module>
from app import main
File "/var/azureml-server/app.py", line 27, in <module>
import main as user_main
File "/var/azureml-app/main.py", line 19, in <module>
driver_module_spec.loader.exec_module(driver_module)
File "/structure/azureml-app/score.py", line 22, in <module>
importlib.import_module("multilabelencoder")
File "/azureml-envs/azureml_b707e8c15a41fd316cf6c660941cf3d5/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'multilabelencoder'
我了解 pickle/joblib 在取消自定义函数 MultiLabelEncoder 时存在一些问题。这就是为什么我在一个单独的 python 脚本(我也执行过)中定义了这个类。我在训练 Python 脚本、部署脚本和评分 Python 文件 (score.py) 中调用了这个自定义函数。 score.py 文件中的导入不成功。 所以我的问题是如何将自定义 python 模块导入 azure ml 部署环境?
提前谢谢你。
编辑: 这是我的 .yml 文件
name: project_environment
dependencies:
# The python interpreter version.
# Currently Azure ML only supports 3.5.2 and later.
- python=3.6.2
- pip:
- multilabelencoder==1.0.4
- scikit-learn
- azureml-defaults==1.0.74.*
- pandas
channels:
- conda-forge
【问题讨论】:
-
能否分享一下环境文件(.yml)进行检查。
标签: python pickle azure-machine-learning-studio azure-machine-learning-service