在IBM Watson中部署笔记本 [英] Deploy notebook in IBM Watson

查看:174
本文介绍了在IBM Watson中部署笔记本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IBM Watson Studio 中有一个python笔记本,用于时间序列预测.

I have a python notebook in IBM Watson Studio for a time series forecasting purpose.

需要两个输入数据

  1. MAX
  2. MIN

,它会返回两个数据列表,这些数据比MAXMIN的预测提前了10个步骤.

and it returns two lists of data having 10 steps ahead prediction of both MAX and MIN.

我想使其可用于外部应用程序.我已经搜索了诸如API创建之类的解决方案,但没有任何来源.有人可以建议我这样做的正确方法或有用的资源吗?

I want to make it available for an external application. I have searched for the solution like API creation but didn't get any source. can anyone suggest me the proper way or helpful resources to do it?

推荐答案

现在,通过2天的研究和尝试,我得到了自己的问题的解决方案.没有人给我任何解决方案,因此我认为将其发布在这里以供将来参考.

Now I got the solution of my own question through my 2 days of research and attempts. Nobody gave me any solution so I thought that it would be posted here for future references.

在这里,我添加了我的实践经验,因此可能会是一个很长的答案.

Here, I have added my practical experience so that it might be a long answer.

1.为什么选择IBM笔记本?

如果需要更多定制,我们选择笔记本而不是可用型号.我们将获得内置模型中不可用的大多数模型

We choose a notebook instead of available models if we need more customization. we will get most of the models that are not available in the built-in models

2.这样做的方式?

根据我的查询,我找到了两种方法来实现

As per my enquiry, I found two ways to do that

  • 将其部署为python函数(为我工作)
  • 借助jupyter笔记本,IBM Cloud和Github进行部署.请参见教程
  • Deploy it as python function ( Worked for me )
  • Deploy it with the help of jupyter notebook, IBM Cloud and Github See this tutorial

3.将其部署为python函数 [来源]

  • 在一个功能下完成所有功能(步骤1 ).就像它接受输入并返回输出一样.

  • Wrap up all your functionalities under a single function (Step 1). like it takes input and returns the output.

在每个调用中,代码中包含的变量或数据结构将丢失数据.因此请避免在python函数中使用这些项目,并在应用程序中对其进行管理.

In each call, the variables or data structures you have in the code will lose the data. so avoid these items in your python function and manage it in your application.

另一个重要的一点是,由于测试环境和部署环境的不同,如果要导入库,则必须将其作为子过程包含在main函数中.您只需添加这样的内容即可

Another important point is that if you want to import libraries you have to include it as a subprocess inside the main function Because of the difference in testing environments and deployed environment. you can do it by simply adding like this

示例格式python函数

def my_deployable_function():

   import subprocess
   subprocess.check_output( "pip install ipython--user",stderr=subprocess.STDOUT,shell=True )

    def score( payload ):

       num1=int(payload["values"][0])
       num2=int(payload["values"][1])  
       ans=num1+num2

    return ans

*在这里,payload是您从API传递给python函数的数据,而ans是输出

*Here, the payload is the data you passed to the python function from the API and ans is the output

测试功能

function_result = my_deployable_function()( { "values" : [ 100,200] } )
print( function_result )

*输入payloaddictionary.根据您的需要,您可以添加元素,但要确保您不更改结构,即,所有内容都应位于单个根元素下,此处为 values .

*Input payload is a dictionary. as per your need, you can add the elements but make sure that you are not changing the structure ie, Everything Should be under a single root element here it is values.

输出

300

  • As you follow (Step 2) in source you need credentials, if you have any problem with existing credentials then create a new one because older one may be expired.

    请遵循官方文档并保留这些说明以节省您的时间.

    Follow the official documentation and keep these instructions to save your time.

    这篇关于在IBM Watson中部署笔记本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆