1

假设我已经有一个 scikit-learn 模型,我想将它保存到我的 Watson Machine Learning 并使用 python 客户端部署它。

python 客户端文档:http ://wml-api-pyclient.mybluemix.net

我喜欢:

clf = svm.SVC(kernel='rbf')
clf.fit(train_data, train_labels)

# Evaluate your model.
predicted = clf.predict(test_data)

我想做的是将此模型部署为可通过 REST API 访问的 Web 服务。

我在这里阅读了 Watson 机器学习文档:https ://dataplatform.cloud.ibm.com/docs/content/analyze-data/wml-ai.html?audience=wdp&context=analytics

但是我在部署模型时遇到了麻烦。

4

2 回答 2

1

借助 scikit 学习模型,Watson Machine Learning 需要一个pipeline对象,而不仅仅是一个拟合模型对象。这样您也可以将数据转换和预处理逻辑部署到同一端点。例如,尝试将您的代码更改为:

scaler = preprocessing.StandardScaler()
clf = svm.SVC(kernel='rbf')
pipeline = Pipeline([('scaler', scaler), ('svc', clf)])
model = pipeline.fit(train_data, train_labels)

然后,您将能够按照此处的文档部署模型:http ://wml-api-pyclient.mybluemix.net/#deployments

在 Watson Studio 中的 Notebook 中,您可以

from watson_machine_learning_client import WatsonMachineLearningAPIClient

wml_credentials = {
                   "url": "https://ibm-watson-ml.mybluemix.net",
                   "username": "*****",
                   "password": "*****",
                   "instance_id": "*****"
                  }

client = WatsonMachineLearningAPIClient(wml_credentials)

然后在先将模型保存到存储库后使用客户端部署模型。

您可以在本教程笔记本中了解如何完成所有这些工作: 来自社区的https://dataplatform.cloud.ibm.com/exchange/public/entry/view/168e65a9e8d2e6174a4e2e2765aa4df1

于 2018-10-03T17:46:29.713 回答
1

您也可以将其部署为 python 函数。您需要的是将所有功能包装到一个可部署的函数中(学习 python 闭包)。

您使用凭证的方式与此方法相同。

  • 第 1 步:定义函数
  • 第 2 步:将函数存储在存储库中

之后,您可以通过两种方式部署和访问

  1. 使用 Python 客户端
  2. 使用 REST API

这已在this中详细解释,请参阅this post

于 2019-05-13T10:39:52.933 回答