2016-10-10 73 views
1

我運行下面的代碼時出現此錯誤。h2o.exceptions.H2OResponseError:服務器錯誤water.exceptions.H2OKeyNotFoundArgumentException

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

回答

1

變化model.startmodel.train(從底部3號線),它應該工作。

model.start()方法的文檔說「異步訓練模型」。這意味着該模型正在後臺進行培訓,並且不能立即用於預測調用。

另一方面,model.train()方法一直等到訓練完成後才繼續。