我已经使用 Sagemaker 框架为 5 个类别训练了一个 Xgboost 多类别分类算法。然后我将模型保存在 S3 上。现在,当我加载它时,我只能选择预测,这将返回类而不是每个类的概率。
pred = xgb_uploaded_model.predict(new_data)
Run Code Online (Sandbox Code Playgroud)
上传的模型没有 predict_proba 选项,这会派上用场。有什么想法可以从这个像这样保存的模型中获得概率吗?PS我不想使用端点。
在表下,AWS Sagemaker 使用三个默认函数进行输入处理、预测和输出处理。人们需要在用于模型训练的Python脚本中重写这些函数。
来自 AWS 文档:
Sagemaker 使用三个默认函数进行模型服务。每个步骤都涉及调用一个 Python 函数,其中包含有关请求的信息以及链中前一个函数的返回值。在 SageMaker Scikit-learn 模型服务器内部,该过程如下所示:
# Deserialize the Invoke request body into an object we can perform prediction on
input_object = input_fn(request_body, request_content_type)
# Perform prediction on the deserialized object, with the loaded model
prediction = predict_fn(input_object, model)
# Serialize the prediction result into the desired response content type
output = output_fn(prediction, response_content_type)
Run Code Online (Sandbox Code Playgroud)
input_fn:获取请求数据并将数据反序列化为对象以进行预测。predict_fn:获取反序列化的请求对象并对加载的模型进行推理。output_fn:获取预测结果并根据响应内容类型对其进行序列化。必须实现 model_fn
如果您的模型使用 .predict() 以外的其他内容,则只需实现 Predict_fn ,这对您的情况很有用
您可以在此处查看默认函数实现的工作原理
参考链接 - Sagemaker sklearn 模型服务
参考链接 - Sagemaker sklearn GitHub 示例
参考链接 - Pytorch 模型服务
| 归档时间: |
|
| 查看次数: |
652 次 |
| 最近记录: |