hello_world.py 2.16 KB
Newer Older
Tiphagne Thomas's avatar
Tiphagne Thomas committed
1

Xu Jitao's avatar
Xu Jitao committed
2
print("hello world")
Tiphagne Thomas's avatar
Tiphagne Thomas committed
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








import h2o
from h2o.automl import H2OAutoML

h2o.init()

train = h2o.import_file("https://s3.amazonaws.com/erin-data/higgs/higgs_train_10k.csv")
test = h2o.import_file("https://s3.amazonaws.com/erin-data/higgs/higgs_test_5k.csv")

x = train.columns
y = "response"
x.remove(y)

train[y] = train[y].asfactor()
test[y] = test[y].asfactor()

aml = H2OAutoML(max_runtime_secs = 130)
aml.train(x = x, y = y, training_frame = train, leaderboard_frame = test)

print(aml.leaderboard)
print(aml.leader)

print(aml.predict(test))
Tiphagne Thomas's avatar
Tiphagne Thomas committed
33

Xu Jitao's avatar
Xu Jitao committed
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import numpy as np
def generate_checkers(nb_app, nb_test, cov=[[0.25,0],[0,0.25]]):
    print(cov)
    xapp=np.ndarray((nb_app*16,2))
    yapp=np.ndarray(nb_app*16)
    xtest=np.ndarray((nb_test*16,2))
    ytest=np.ndarray(nb_test*16)

    y=1
    index_app=0
    index_test=0
    for i in range(0,4):
        for j in range(0,4):
            center = [i,j]
            y = 1 if (i+j) % 2 else -1
            xapp[index_app:index_app+nb_app] = np.random.multivariate_normal(center,cov,nb_app)
            yapp[index_app:index_app+nb_app] = np.ones(nb_app)*y
            
            xtest[index_test:index_test+nb_test] = np.random.multivariate_normal(center,cov,nb_test)
            ytest[index_test:index_test+nb_test] = np.ones(nb_test)*y

            index_test += nb_test
            index_app += nb_app
          
    return xapp, yapp, xtest, ytest

def generate_linear_separable_case(nb_app,nb_test):
    from sklearn.datasets import make_blobs
    x, y = make_blobs(n_samples=nb_app+nb_test, centers=2, n_features=2)
    x_app = x[0:nb_app,:]
    y_app = y[0:nb_app].astype(np.int64)
    
    x_test = x[nb_app:,:]
    y_test = y[nb_app:]
    
    y_app[y_app == 0] = -1
    y_test[y_test == 0 ] = -1
    return x_app, y_app, x_test, y_test

def generate_xor(nb_app,nb_test):
    np.random.seed(0)
    x_app = np.random.randn(nb_app, 2)
    y_app = np.logical_xor(x_app[:, 0] > 0, x_app[:, 1] > 0).astype(int)
    y_app[y_app == 0] = -1
    
    np.random.seed(0)
    x_test = np.random.randn(nb_test, 2)
    y_test = np.logical_xor(x_test[:, 0] > 0, x_test[:, 1] > 0).astype(int)
    y_test[y_test == 0] = -1
    
    return x_app,y_app,x_test,y_test
Tiphagne Thomas's avatar
Tiphagne Thomas committed
85