Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save normanlmfung/8fe0ad44b4e7d6b273479c839b829511 to your computer and use it in GitHub Desktop.
Save normanlmfung/8fe0ad44b4e7d6b273479c839b829511 to your computer and use it in GitHub Desktop.
keras_simplest_example
import numpy as np
from keras.models import Sequential
from keras.layers import Dense
X_train = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
y_train = np.array([[0], [1], [1], [0]])
model = Sequential()
model.add(Dense(2, input_dim=2, activation='relu'))
model.add(Dense(1, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=1000, verbose=0)
X_test = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
predictions = model.predict(X_test)
print("Predictions:")
print(predictions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment