【问题标题】:How can I deploy a scikit learn python model with Watson Studio and Machine Learning?如何使用 Watson Studio 和机器学习部署 scikit learn python 模型?
【发布时间】:2019-03-09 00:38:12
【问题描述】:

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


    【解决方案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 来自社区

    【讨论】:

    • 您在 4 分钟内提出并回答了自己的问题?对于刚接触该网站的人来说还不错。 . .
    【解决方案2】:

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

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

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

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

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

    这个see this post已经详细解释了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-18
      • 2020-12-10
      • 2018-07-07
      • 2019-02-08
      • 2017-08-22
      • 1970-01-01
      • 2019-04-16
      • 2015-06-19
      相关资源
      最近更新 更多