Reputation: 2115
I get this error when I run the code below.
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)
The specific error is:
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
There are no other errors prior to this one.
H2O Version: 3.11.0.3645
Python Version: 3.4.4
Upvotes: 1
Views: 5806
Reputation: 29
All you have to do is to shutdown the existing cluster if one is open and running.
h2o.cluster.shutdown()
And restart / reinitiate cluster using
h2o.init()
Upvotes: 2
Reputation: 6560
Change model.start
into model.train
(3rd line from the bottom), and it should work.
The documentation for model.start()
method says "Train the model asynchronously". This means that the model is being trained in the background and is not available right away for the prediction call.
The model.train()
method on the other hand waits until the training is completed before continuing.
Upvotes: 1