forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h2o_nn.py
39 lines (28 loc) · 1.86 KB
/
h2o_nn.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
import h2o_cmd, h2o, h2o_util
import re, random, math
## Check that the last scored validation error is within a certain relative error of the expected result
def checkLastValidationError(self, model, rows, expectedErr, relTol, **kwargs):
errsLast = model['validation_errors'][-1] # last scoring result
h2o.verboseprint("NN 'Last scoring on test set:'", h2o.dump_json(errsLast))
expectedSamples = rows * kwargs['epochs']
print 'Expecting ' + format(expectedSamples) + ' training samples'
if errsLast['training_samples'] != expectedSamples:
raise Exception("Number of training samples should be equal to %s" % expectedSamples)
print "Expected test set error: " + format(expectedErr)
print "Actual test set error: " + format(errsLast['classification'])
if errsLast['classification'] != expectedErr and abs((expectedErr - errsLast['classification'])/expectedErr) > relTol:
raise Exception("Test set classification error of %s is not within %s %% relative error of %s" % (errsLast['classification'], float(relTol)*100, expectedErr))
warnings = None
# shouldn't have any errors
h2o.check_sandbox_for_errors()
return (warnings)
## Check that the scored validation error is within a certain relative error of the expected result
def checkScoreResult(self, result, expectedErr, relTol, **kwargs):
print "Expected score error: " + format(expectedErr)
print "Actual score error: " + format(result['classification_error'])
if result['classification_error'] != expectedErr and abs((expectedErr - result['classification_error'])/expectedErr) > relTol:
raise Exception("Scored classification error of %s is not within %s %% relative error of %s" % (result['classification_error'], float(relTol)*100, expectedErr))
warnings = None
# shouldn't have any errors
h2o.check_sandbox_for_errors()
return (warnings)