python - 从现有系数创建 H2OGeneralizedLinearEstimator 实例
问题描述
我有一组来自训练模型的系数,但我无法访问模型本身或训练数据集。我想创建一个实例H2OGeneralizedLinearEstimator
并手动设置系数以使用模型进行预测。
我尝试的第一件事是(这是重现错误的示例):
import h2o
from h2o.estimators.glm import H2OGeneralizedLinearEstimator
from h2o.frame import H2OFrame
h2o.init()
# creating some test dataset
test = {"x":[0,1,2], "y":[0,0,1]}
df = H2OFrame(python_obj=test)
glm = H2OGeneralizedLinearEstimator(family='binomial', model_id='logreg')
# setting the coefficients
glm.coef = {'Intercept':0, 'x':1}
# predict
glm.predict(test_data=df)
这会引发错误:
H2OResponseError:服务器错误 water.exceptions.H2OKeyNotFoundArgumentException:错误:函数中未找到对象“logreg”:预测参数:模型
我还尝试glm.params
根据类似训练模型的键设置键:
for key in trained.params.keys():
glm.params.__setitem__(key, trained.params[key])
但这不会填充glm.params
( glm.params = {}
)。
解决方案
看起来你想使用函数makeGLMModel
这在文档中有进一步的描述,为了您的方便,我将在这里重新发布:
修改或创建自定义 GLM 模型
在 R 和 python 中,该makeGLMModel
调用可用于根据给定系数创建 H2O 模型。它需要在同一数据集上训练的源 GLM 模型来提取数据集信息。要从 R 或 python 制作自定义 GLM 模型:
- R:打电话
h2o.makeGLMModel
。这需要一个模型、一个系数向量和(可选的)决策阈值作为参数。 - Pyton:(
H2OGeneralizedLinearEstimator.makeGLMModel
静态方法)将模型、包含系数的字典和(可选)决策阈值作为参数。
推荐阅读
- numpy - 在 TensorFlow Graph 中使用 scipy.stats.entropy
- performance - Haskell中的Eratosthenes执行时间筛
- php - Prestashop 1.6.1.15 - 覆盖控制器问题
- google-sheets - Google 表格:Arrayformula 以相反的顺序生成日期
- sql - 根据条件查找既存在又不存在的值(SQL Server)
- php - 带有 ES256 的 php openssl_sign 创建无效签名
- git - 忽略的大 node_module 仍然尝试推送到 repo
- python - Python语音识别错误 - 通道数无效
- c# - 无法使用非托管导出导出 C# DLL 中的函数
- python - 如何比较 CSV 列数据