Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.