如何在 AI 平台上检索 google 自定义例程中的预测 class?
How can I retrieve the prediction class in google custom routine on AI platform?
对于每个实例,我想检索每个预测的概率 class。
我正在 Google AI 平台上构建自定义预测例程:
import os
import joblib
class lr_predictor(object):
def __init__(self,model):
self._model = model
def predict(self, instances, **kwargs):
class_names = self._model.classes_
if kwargs.get('probabilities'):
probabilities = self._model.predict_proba(instances)
return (class_names,probabilities.tolist())
else:
outputs = self._model.predict(instances)
return outputs
@classmethod
def from_path(cls,model_dir):
model_path = os.path.join(model_dir,'model.joblib')
model = joblib.load(model_path)
return cls(model)
如何进行这项工作?
预测 class 应遵循 Predictor Class 上定义的实现。此接口将告诉 AI-Platform 如何处理预测请求。
我已经编制了一份官方笔记本文档列表,可以指导您完成预测 class:
- Custom Prediction Routines
- Get started with Custom Prediction Routine
- Creating a custom prediction routine with scikit-learn
注意:预测器class稍后用于部署custom prediction routine。
对于每个实例,我想检索每个预测的概率 class。
我正在 Google AI 平台上构建自定义预测例程:
import os
import joblib
class lr_predictor(object):
def __init__(self,model):
self._model = model
def predict(self, instances, **kwargs):
class_names = self._model.classes_
if kwargs.get('probabilities'):
probabilities = self._model.predict_proba(instances)
return (class_names,probabilities.tolist())
else:
outputs = self._model.predict(instances)
return outputs
@classmethod
def from_path(cls,model_dir):
model_path = os.path.join(model_dir,'model.joblib')
model = joblib.load(model_path)
return cls(model)
如何进行这项工作?
预测 class 应遵循 Predictor Class 上定义的实现。此接口将告诉 AI-Platform 如何处理预测请求。
我已经编制了一份官方笔记本文档列表,可以指导您完成预测 class:
- Custom Prediction Routines
- Get started with Custom Prediction Routine
- Creating a custom prediction routine with scikit-learn
注意:预测器class稍后用于部署custom prediction routine。