Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@semihyagcioglu
Last active April 28, 2017 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save semihyagcioglu/ba151a3781b401eee0a6a41d4c343cd3 to your computer and use it in GitHub Desktop.
Save semihyagcioglu/ba151a3781b401eee0a6a41d4c343cd3 to your computer and use it in GitHub Desktop.
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense
X = np.array([[0,0],[0,1],[1,0],[1,1]]) # training data, the states of the XOR gate
y = np.array([[0],[1],[1],[0]]) # true labels of the data in the same order
model = Sequential()
model.add(Dense(16, input_dim=2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['binary_accuracy'])
model.fit(X, y, batch_size=1, nb_epoch=1000, verbose=2)
print(model.predict(X).round())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment