Skip to content

Instantly share code, notes, and snippets.

@emilwallner
Last active October 5, 2017 18:00
Show Gist options
  • Save emilwallner/7a34a7e6dd14c3cbb5cac805a6a26161 to your computer and use it in GitHub Desktop.
Save emilwallner/7a34a7e6dd14c3cbb5cac805a6a26161 to your computer and use it in GitHub Desktop.
# 1. Import library of functions
import tflearn
# 2. Logical OR operator / the data
OR = [[0., 0.], [0., 1.], [1., 0.], [1., 1.]]
Y_truth = [[0.], [1.], [1.], [1.]]
# 3. Building our neural network/layers of functions
neural_net = tflearn.input_data(shape=[None, 2])
neural_net = tflearn.fully_connected(neural_net, 1, activation='sigmoid')
neural_net = tflearn.regression(neural_net, optimizer='sgd', learning_rate=2, loss='mean_square')
# 4. Train the neural network / Epochs
model = tflearn.DNN(neural_net)
model.fit(OR, Y_truth, n_epoch=2000, snapshot_epoch=False)
# 5. Testing final prediction
print("Testing OR operator")
print("0 or 0:", model.predict([[0., 0.]]))
print("0 or 1:", model.predict([[0., 1.]]))
print("1 or 0:", model.predict([[1., 0.]]))
print("1 or 1:", model.predict([[1., 1.]]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment