h2o.exceptions.H2OResponseError:服务器错误water.exceptions.H2OKeyNotFoundArgumentException

问题描述 投票:1回答:2

我运行下面的代码时出现此错误。

import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator as GBM
from sklearn import datasets
import numpy as np
import pandas as pd

h2o.init(ip='192.168.0.4',port=54321)

# writing data to CSV so that h2o can read it
digits = datasets.load_digits()
predictors = digits.data[:-1]
targets = digits.target[:-1]
record_count = targets.shape[0]
targets = targets.reshape([record_count,1])
data = predictors
data = np.concatenate((data, targets), axis=1)
write_df = pd.DataFrame(data).to_csv(path_or_buf='data.csv',index=False)
model = GBM(ntrees=3,distribution='multinomial',max_depth=3)
everything = h2o.import_file(path='data.csv')
everything[64] = everything[64].asfactor()
model.start(training_frame=everything,x=list(range(64)),y=64,validation_frame=everything)

# model seems to be None for some reason
predictions = model.predict(everything)

具体错误是:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/ryanzotti/anaconda/lib/python3.4/site-packages/h2o/model/model_base.py", line 148, in predict
    j = H2OJob(h2o.api("POST /4/Predictions/models/%s/frames/%s" % (self.model_id, test_data.frame_id)),
  File "/Users/ryanzotti/anaconda/lib/python3.4/site-packages/h2o/h2o.py", line 83, in api
    return h2oconn.request(endpoint, data=data, json=json, filename=filename, save_to=save_to)
  File "/Users/ryanzotti/anaconda/lib/python3.4/site-packages/h2o/backend/connection.py", line 259, in request
    return self._process_response(resp, save_to)
  File "/Users/ryanzotti/anaconda/lib/python3.4/site-packages/h2o/backend/connection.py", line 586, in _process_response
    raise H2OResponseError(data)
h2o.exceptions.H2OResponseError: Server error water.exceptions.H2OKeyNotFoundArgumentException:
  Error: Object 'None' not found in function: predict for argument: model
  Request: POST /4/Predictions/models/None/frames/py_1_sid_a5e2

在此之前没有其他错误。

H2O版本:3.11.0.3645

Python版本:3.4.4

python h2o
2个回答
1
投票

model.start改为model.train(从底部开始的第3行),它应该有效。

model.start()方法的文档说“异步训练模型”。这意味着模型正在后台进行训练,并且无法立即用于预测调用。

另一方面,model.train()方法等待训练完成后再继续。


3
投票

您所要做的就是在现有集群打开并运行时关闭现有集群。

h2o.cluster.shutdown()

并使用重新启动/重新启动群集

h2o.init()
© www.soinside.com 2019 - 2024. All rights reserved.