forked from h2oai/h2o-2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh2o_nn.py
50 lines (37 loc) · 2.25 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
40
41
42
43
44
45
46
47
48
49
50
import h2o_cmd, h2o_util
import re, random, math
from h2o_test import verboseprint, dump_json, check_sandbox_for_errors
def pickRandDeepLearningParams(paramDict, params):
randomGroupSize = random.randint(1,len(paramDict))
for i in range(randomGroupSize):
randomKey = random.choice(paramDict.keys())
randomV = paramDict[randomKey]
randomValue = random.choice(randomV)
params[randomKey] = randomValue
return
## 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
verboseprint("Deep Learning 'Last scoring on test set:'", 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
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
check_sandbox_for_errors()
return (warnings)