Last active
October 5, 2017 18:00
-
-
Save emilwallner/7a34a7e6dd14c3cbb5cac805a6a26161 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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