Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from Network import NeuralNetwork
- def read_file(filename):
- with open(filename) as f:
- content = f.readlines()
- X = []
- y = []
- for i in content:
- X.append([float(num) for num in i.strip().split()[:-1]])
- y.append(i.strip().split()[-1:])
- return (X, y)
- if __name__ == "__main__":
- (X, _y) = read_file("column_2C.dat")
- y = []
- for i in _y:
- if i[0] == 'NO':
- y.append([0,1])
- if i[0] == 'AB':
- y.append([1,0])
- M = np.amax(X, axis=0)
- N = np.amin(X, axis=0)
- _X = (X - N) / (M - N)
- _y = y
- X = np.array(_X[:298])
- y = np.array(_y[:298])
- nn = NeuralNetwork(X, y)
- for i in range(1500):
- nn.feedforward()
- nn.backprop()
- k = 0
- correct = 0
- nn.input = np.array(_X[298:])
- nn.feedforward()
- for i in nn.output:
- print(i, end=" Resulted: ")
- if i[0] > i[1]:
- print("AB", end=" Expected: ")
- if (_y[298:][k][0] == 1):
- print("AB")
- correct += 1
- print("CORRECT")
- else:
- print("NO")
- print("WRONG")
- else:
- print("NO", end=" Expected: ")
- if (_y[298:][k][0] == 0):
- print("NO")
- correct += 1
- print("CORRECT")
- else:
- print("AB")
- print("WRONG")
- k += 1
- print("ACCURACY: ", end="")
- print(correct/(310-298))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement