-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeras_practice.py
More file actions
39 lines (29 loc) · 897 Bytes
/
Keras_practice.py
File metadata and controls
39 lines (29 loc) · 897 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 22 00:02:46 2018
@author: zhaow
"""
import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.optimizers import SGD
def keras_learn(X, Y):
np.random.seed(0)
"""モデルの設定"""
model = Sequential()
model.add(Dense(input_dim=2, units=1))
model.add(Activation('sigmoid'))
model.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.1))
model.fit(X, Y, epochs=200, batch_size=1)
"""学習結果の確認"""
classes = model.predict_classes(X, batch_size=1)
prob = model.predict_proba(X, batch_size=1)
print('classifed')
print(Y == classes)
print()
print('output probability')
print(prob)
if __name__ == '__main__':
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([[0], [1], [1], [1]])
keras_learn(X, Y)