Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
from keras.models import Sequential
from keras.layers.core import Dense, Activation
xoder={
(0,0):0,
(0,1):1,
(1,0):1,
(1,1):0
}
X=input=np.array([[0,0],[0,1],[1,0],[1,1]])
Y=output=np.array([[1,0],[0,1],[0,1],[1,0]])
model = Sequential()
model.add(Dense(10, input_shape=(2,)))
model.add(Activation('relu'))
model.add(Dense(40))
model.add(Activation('relu'))
model.add(Dense(2))
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam',metrics=['acc'])
model.fit(input,output,epochs=200)
result=model.predict(np.array([[0,1]]))
print(result)
print(np.argmax(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment