Advertisement
Guest User

Untitled

a guest
May 18th, 2021
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. from keras.models import Sequential
  2. from keras.layers.core import Dense, Dropout, Activation
  3. from keras.optimizers import SGD
  4. import numpy as np
  5.  
  6. #X = np.array([[0,0],[0,1],[1,0],[1,1]])
  7. #y = np.array([[1,0],[0,1],[0,1],[1,0]])
  8.  
  9. X = np.array([[0,0],[0,1],[1,0],[1,1]])
  10. 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]])
  11.  
  12. model = Sequential()
  13. model.add(Dense(8, input_dim=2))
  14. model.add(Activation('tanh'))
  15. model.add(Dense(3))
  16. model.add(Activation('softmax'))
  17.  
  18. sgd = SGD(learning_rate=0.05)
  19. model.compile(loss='categorical_crossentropy', optimizer=sgd)
  20.  
  21. model.fit(X, y, epochs=10000)
  22. np.set_printoptions(precision=3, suppress=True)
  23. print(model.predict(X))
  24. """
  25. [[ 0.0033028 ]
  26. [ 0.99581173]
  27. [ 0.99530098]
  28. [ 0.00564186]]
  29. """
  30.  
  31. #0.198 0.024 0.777
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement