首页 > 解决方案 > 如何使用 Watson Studio 和机器学习部署 scikit learn python 模型?

问题描述

假设我已经有一个 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

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

标签: machine-learningwatson-studio

解决方案


借助 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


推荐阅读