Advertisement
Guest User

Untitled

a guest
May 24th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. import numpy as np
  2. from Network import NeuralNetwork
  3.  
  4. def read_file(filename):
  5. with open(filename) as f:
  6. content = f.readlines()
  7. X = []
  8. y = []
  9. for i in content:
  10. X.append([float(num) for num in i.strip().split()[:-1]])
  11. y.append(i.strip().split()[-1:])
  12. return (X, y)
  13.  
  14. if __name__ == "__main__":
  15. (X, _y) = read_file("column_2C.dat")
  16. y = []
  17. for i in _y:
  18. if i[0] == 'NO':
  19. y.append([0,1])
  20. if i[0] == 'AB':
  21. y.append([1,0])
  22.  
  23. M = np.amax(X, axis=0)
  24. N = np.amin(X, axis=0)
  25. _X = (X - N) / (M - N)
  26.  
  27. _y = y
  28.  
  29. X = np.array(_X[:298])
  30. y = np.array(_y[:298])
  31.  
  32. nn = NeuralNetwork(X, y)
  33.  
  34. for i in range(1500):
  35. nn.feedforward()
  36. nn.backprop()
  37.  
  38. k = 0
  39. correct = 0
  40. nn.input = np.array(_X[298:])
  41. nn.feedforward()
  42.  
  43. for i in nn.output:
  44. print(i, end=" Resulted: ")
  45. if i[0] > i[1]:
  46. print("AB", end=" Expected: ")
  47. if (_y[298:][k][0] == 1):
  48. print("AB")
  49. correct += 1
  50. print("CORRECT")
  51. else:
  52. print("NO")
  53. print("WRONG")
  54. else:
  55. print("NO", end=" Expected: ")
  56. if (_y[298:][k][0] == 0):
  57. print("NO")
  58. correct += 1
  59. print("CORRECT")
  60. else:
  61. print("AB")
  62. print("WRONG")
  63. k += 1
  64. print("ACCURACY: ", end="")
  65. print(correct/(310-298))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement