/
pyunit_checkpoint_new_category_in_predictorDL.py
41 lines (32 loc) · 1.59 KB
/
pyunit_checkpoint_new_category_in_predictorDL.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys, os
sys.path.insert(1, os.path.join("..","..",".."))
import h2o
from tests import pyunit_utils
from h2o.estimators.deeplearning import H2ODeepLearningEstimator
#TODO(vlad): this test randomly fails with no meaningful messages. Tracking it.
def checkpoint_new_category_in_predictor():
sv1 = h2o.upload_file(pyunit_utils.locate("smalldata/iris/setosa_versicolor.csv"))
sv2 = h2o.upload_file(pyunit_utils.locate("smalldata/iris/setosa_versicolor.csv"))
vir = h2o.upload_file(pyunit_utils.locate("smalldata/iris/virginica.csv"))
print("checkpoint_new_category_in_predictor-1")
m1 = H2ODeepLearningEstimator(epochs=100)
m1.train(x=[0,1,2,4], y=3, training_frame=sv1)
m2 = H2ODeepLearningEstimator(epochs=200, checkpoint=m1.model_id)
m2.train(x=[0,1,2,4], y=3, training_frame=sv2)
print("checkpoint_new_category_in_predictor-2")
# attempt to continue building model, but with an expanded categorical predictor domain.
# this should fail
try:
m3 = H2ODeepLearningEstimator(epochs=200, checkpoint=m1.model_id)
m3.train(x=[0,1,2,4], y=3, training_frame=vir)
assert False, "Expected continued model-building to fail with new categories introduced in predictor"
except EnvironmentError:
pass
print("checkpoint_new_category_in_predictor-3")
# attempt to predict on new model, but with observations that have expanded categorical predictor domain.
predictions = m2.predict(vir)
print("checkpoint_new_category_in_predictor-4")
if __name__ == "__main__":
pyunit_utils.standalone_test(checkpoint_new_category_in_predictor)
else:
checkpoint_new_category_in_predictor()