Skip to content

Instantly share code, notes, and snippets.

@skyer9
Created April 22, 2017 11:10
Show Gist options
  • Save skyer9/a6695b49d9ebd428fc7196559770a9ea to your computer and use it in GitHub Desktop.
Save skyer9/a6695b49d9ebd428fc7196559770a9ea to your computer and use it in GitHub Desktop.
from keras.models import Sequential
from keras.layers import Dense
from keras.optimizers import SGD
import numpy as np
x_data = [[0, 0, 0],
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
[1, 1, 0],
[1, 0, 1]]
y_data = [[0],
[1],
[0],
[0],
[1],
[1]]
model = Sequential()
model.add(Dense(1, input_dim=3, activation='sigmoid'))
sgd = SGD(lr=0.1)
model.compile(loss='binary_crossentropy', optimizer=sgd)
model.summary()
model.fit(x_data, y_data, epochs=1000)
print("[1, 1, 1]", model.predict_classes(np.array([[1, 1, 1]])))
print("[0, 1, 1]", model.predict_classes(np.array([[0, 1, 1]])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment