-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (27 loc) · 909 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from NeuralNetwork import NeuralNetwork
""" Which dataset would you like to test?"""
# 0 = Iris dataset
# 1 = Pima Indians dataset
dataset = 0
if dataset == 0:
filename = "datasets/iris.data"
targets = ['Iris-setosa', 'Iris-virginica', 'Iris-versicolor']
elif dataset == 1:
filename = "datasets/pima-indians-diabetes.data"
targets = [0, 1]
# Create the network
nn = NeuralNetwork()
nn.loadDataset(filename)
nn.normalize()
nn.createNetwork([2, 3], targets)
numCorrect = 0
# Make the predictions
for i in range(1):
nn.feed(nn.testingSet[i])
print("Instance", i + 1, ": predicted =", nn.getClassification(), "actual =", nn.testingSet[i][-1])
if nn.getClassification() == nn.testingSet[i][-1]:
numCorrect += 1
nn.propagateBack()
# Output the accuracy
accuracy = (float(numCorrect) / len(nn.testingSet)) * 100.0
print("Accuracy:", float("{0:.1f}".format(accuracy)), '%')