-
Notifications
You must be signed in to change notification settings - Fork 2k
/
pyunit_deeplearning_metrics.py
42 lines (33 loc) · 1.19 KB
/
pyunit_deeplearning_metrics.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
import sys
sys.path.insert(1, "..")
import h2o
def deep_learning_metrics_test(ip, port):
h2o.init(ip, port) # connect to existing cluster
df = h2o.import_frame(path=h2o.locate("smalldata/logreg/prostate.csv"))
df.drop("ID") # remove ID
df['CAPSULE'] = df['CAPSULE'].asfactor() # make CAPSULE categorical
vol = df['VOL']
vol[vol == 0] = float("nan") # 0 VOL means 'missing'
r = vol.runif() # random train/test split
train = df[r < 0.8]
test = df[r >= 0.8]
# See that the data is ready
train.describe()
train.head()
train.tail()
test.describe()
test.head()
test.tail()
# Run DeepLearning
print "Train a Deeplearning model: "
dl = h2o.deeplearning(x = train[1:],
y = train['CAPSULE'],
epochs = 100,
hidden = [10, 10, 10],
loss = 'CrossEntropy')
print "Binomial Model Metrics: "
print
dl.show()
dl.model_performance(test).show()
if __name__ == "__main__":
h2o.run_test(sys.argv, deep_learning_metrics_test)