03_03_mlp_xor

原创 2018年04月15日 22:04:27

import numpy as np
from keras.models import Sequential
from keras.layers import Dense, Activation
from keras.optimizers import SGD

np.random.seed(123)

X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([[0], [1], [1], [0]])

model = Sequential()
model.add(Dense(input_dim=2, units=2))
model.add(Activation('sigmoid'))
model.add(Dense(units=1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy', optimizer=SGD(lr=0.1))

model.fit(X, Y, epochs=4000, batch_size=4)

classes = model.predict_classes(X, batch_size=4)
prob = model.predict_proba(X, batch_size=4)

print('classified:')
print(Y == classes)
print()
print('output probability:')
print(prob)


classified:
[[ True]
 [ True]
 [ True]
 [ True]]


output probability:
[[0.08179113]
 [0.8161889 ]
 [0.8167798 ]
 [0.24346064]]




收藏助手
不良信息举报
您举报文章:03_03_mlp_xor
举报原因:
原因补充:

(最多只允许输入30个字)