Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from keras.models import Sequential
- from keras.layers.core import Dense, Dropout, Activation
- from keras.optimizers import SGD
- import numpy as np
- #X = np.array([[0,0],[0,1],[1,0],[1,1]])
- #y = np.array([[1,0],[0,1],[0,1],[1,0]])
- X = np.array([[0,0],[0,1],[1,0],[1,1]])
- y = np.array([[0.2,0.0,0.8],[0.0,1.0,0.0],[0.15,0.25,0.6],[0.1,0.2,0.7]])
- model = Sequential()
- model.add(Dense(8, input_dim=2))
- model.add(Activation('tanh'))
- model.add(Dense(3))
- model.add(Activation('softmax'))
- sgd = SGD(learning_rate=0.05)
- model.compile(loss='categorical_crossentropy', optimizer=sgd)
- model.fit(X, y, epochs=10000)
- np.set_printoptions(precision=3, suppress=True)
- print(model.predict(X))
- """
- [[ 0.0033028 ]
- [ 0.99581173]
- [ 0.99530098]
- [ 0.00564186]]
- """
- #0.198 0.024 0.777
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement