Created
March 30, 2024 22:07
-
-
Save normanlmfung/8fe0ad44b4e7d6b273479c839b829511 to your computer and use it in GitHub Desktop.
keras_simplest_example
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
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