Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. import numpy as np
  2. from sklearn import datasets
  3. from sklearn import preprocessing
  4. from sklearn.utils import shuffle
  5. from matplotlib import pyplot as plt
  6.  
  7. import math
  8.  
  9. np.set_printoptions(threshold=np.inf)
  10.  
  11.  
  12. # load dataset
  13. iris = datasets.load_iris()
  14. X, labels = iris.data, iris.target
  15. X, labels = shuffle(X, labels)
  16. onehot_encoder = preprocessing.OneHotEncoder(sparse=False)
  17. labels = labels.reshape(-1, 1)
  18.  
  19. # normalize input data
  20. X = 2.0 * X / np.max(X) - 1.0
  21. Y = onehot_encoder.fit_transform(labels)
  22.  
  23. # insert activation function and derivative here
  24.  
  25. # randomly initialize weights with mean 0
  26.  
  27.  
  28. losses = []
  29. for epoch in range(100):
  30. for j in range(len(X)):
  31. # forward pass
  32.  
  33. # error
  34. error = ...
  35.  
  36. # backward pass
  37.  
  38. # weights update
  39.  
  40. losses.append(np.sum(np.abs(error)))
  41.  
  42. plt.plot(losses)
  43. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement