machine-learning - 如何使用 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
但是我在部署模型时遇到了麻烦。
解决方案
借助 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
推荐阅读
- azure - 将 ADF 用于 REST API
- amazon-web-services - lambda 添加权限 - S3 存储桶的账户 ID
- javascript - 在 Angular 中使用来自服务器的数据修补 FormArrays 值的问题
- python-3.x - AttributeError:模块“tensorflow”没有属性“get_default_graph”。向模型添加新层时出现此错误
- c# - 使用 .NET 从另一个 XML 文件附加一个 XML 节点
- html - 如何在roundcube上自定义登录页面
- vue.js - Vue:在路由上第二次不渲染组件
- python - PNG图像包含高达40,000的像素值?
- c++ - 使用控制台菜单显示不同 OpenCV 过滤器的切换案例
- docker - 在 Windows Server 2019 上运行 Linux Docker 容器