Skip to content

Commit ae65e3f

Browse files
author
继盛
committed
upgrade to 0.8.3
1 parent 39dd4db commit ae65e3f

29 files changed

+756
-1971
lines changed

docs/source/api-def.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ Definitions
5454
.. autoclass:: odps.models.ml.OfflineModel
5555
:members:
5656

57-
.. autoclass:: odps.models.ml.OnlineModel
58-
:members:
59-
6057
.. autoclass:: odps.models.security.User
6158
:members:
6259

docs/source/base-models.rst

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -98,110 +98,3 @@ run_xflow 的例子:
9898
.. code:: python
9999
100100
>>> o.delete_offline_model('logistic_regression_model_name')
101-
102-
在线模型
103-
---------
104-
105-
在线模型是 ODPS 提供的模型在线部署能力。用户可以通过 Pipeline 部署自己的模型。详细信息请参考“机器学习平台——在线服务”章节。
106-
107-
需要注意的是,在线模型的服务使用的是独立的 Endpoint,需要配置 Predict Endpoint。通过
108-
109-
.. code:: python
110-
111-
>>> o = ODPS('your-access-id', 'your-secret-access-key', 'your-default-project',
112-
>>> endpoint='your-end-point', predict_endpoint='predict_endpoint')
113-
114-
即可在 ODPS 对象上添加相关配置。Predict Endpoint 的地址请参考相关说明或咨询管理员。
115-
116-
部署离线模型上线
117-
~~~~~~~~~~~~~~~~
118-
119-
PyODPS 提供了离线模型的部署功能。部署方法为
120-
121-
.. code:: python
122-
123-
>>> model = o.create_online_model('online_model_name', 'offline_model_name')
124-
125-
126-
部署自定义 Pipeline 上线
127-
~~~~~~~~~~~~~~~~~~~~~~~~
128-
含有自定义 Pipeline 的在线模型可自行构造 ModelPredictor 对象,例子如下:
129-
130-
.. code:: python
131-
132-
>>> from odps.models.ml import ModelPredictor, ModelProcessor, BuiltinProcessor, PmmlProcessor, PmmlRunMode
133-
>>> predictor = ModelPredictor(target_name='label')
134-
>>> predictor.pipeline.append(BuiltinProcessor(offline_model_name='sample_offlinemodel',
135-
>>> offline_model_project='online_test'))
136-
>>> predictor.pipeline.append(PmmlProcessor(pmml='data_preprocess.xml',
137-
>>> resources='online_test/resources/data_preprocess.xml',
138-
>>> run_mode=PmmlRunMode.Converter))
139-
>>> predictor.pipeline.append(CustomProcessor(class_name='SampleProcessor',
140-
>>> lib='libsample_processor.so',
141-
>>> resources='online_test/resources/sample_processor.tar.gz'))
142-
>>> model = o.create_online_model('online_model_name', predictor)
143-
144-
其中,BuiltinProcessor、PmmlProcessor 和 CustomProcessor 分别指 ODPS OfflineModel 形成的 Pipeline 节点、PMML
145-
模型文件形成的 Pipeline 节点和用户自行开发的 Pipeline 节点。
146-
147-
在线模型操作
148-
~~~~~~~~~~~~
149-
150-
与其他 ODPS 对象类似,创建后,可列举、获取和删除在线模型:
151-
152-
.. code:: python
153-
154-
>>> models = o.list_online_models(prefix='prefix')
155-
>>> model = o.get_online_model('online_model_name')
156-
>>> o.delete_online_model('online_model_name')
157-
158-
可使用模型名和数据进行在线预测,输入数据可以是 Record,也可以是字典或数组和 Schema 的组合:
159-
160-
.. code:: python
161-
162-
>>> data = [[4, 3, 2, 1], [1, 2, 3, 4]]
163-
>>> result = o.predict_online_model('online_model_name', data,
164-
>>> schema=['sepal_length', 'sepal_width', 'petal_length', 'petal_width'])
165-
166-
也可为模型设置 ABTest。参数中的 modelx 可以是在线模型名,也可以是 get_online_model 获得的模型对象本身,而 percentagex 表示
167-
modelx 在 ABTest 中所占的百分比,范围为 0 至 100:
168-
169-
.. code:: python
170-
171-
>>> result = o.config_online_model_ab_test('online_model_name', model1, percentage1, model2, percentage2)
172-
173-
修改模型参数可以通过修改 OnlineModel 对象的属性,再调用 update 方法实现,如
174-
175-
.. code:: python
176-
177-
>>> model = o.get_online_model('online_model_name')
178-
>>> model.cpu = 200
179-
>>> model.update()
180-
181-
与其他对象不同的是,在线模型的创建和删除较为耗时。PyODPS 默认 create_online_model 和 delete_online_model 以及
182-
OnlineModel 的 update 方法在整个操作完成后才返回。用户可以通过 async 选项控制是否要在模型创建请求提交后立即返回,
183-
然后自己控制等待。例如,下列语句
184-
185-
.. code:: python
186-
187-
>>> model = o.create_online_model('online_model_name', 'offline_model_name')
188-
189-
等价于
190-
191-
.. code:: python
192-
193-
>>> model = o.create_online_model('online_model_name', 'offline_model_name', async=True)
194-
>>> model.wait_for_service()
195-
196-
197-
198-
.. code:: python
199-
200-
>>> o.delete_online_model('online_model_name')
201-
202-
等价于
203-
204-
.. code:: python
205-
206-
>>> o.delete_online_model('* online_model_name *', async=True)
207-
>>> model.wait_for_deletion()

0 commit comments

Comments
 (0)