Created
September 11, 2016 06:18
-
-
Save codekansas/1936a02d9ce6475ea58cd73cbddcc98b to your computer and use it in GitHub Desktop.
Two-layer XOR in Keras
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import numpy as np | |
from keras.engine import Input, Model | |
from keras.layers import Dense | |
X = np.asarray([[0, 1], [1, 0], [0, 0], [1, 1]]) | |
y = np.asarray([[0], [0], [1], [1]]) | |
input = Input(shape=(2,)) | |
hidden = Dense(5, activation='relu')(input) | |
output = Dense(1, activation='sigmoid')(hidden) | |
model = Model(input=input, output=output) | |
model.compile(optimizer='sgd', loss='mse') | |
model.fit([X], [y], nb_epoch=10000, verbose=0) | |
error = model.evaluate([X], [y]) | |
print('Error: {}'.format(error)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment