-
Notifications
You must be signed in to change notification settings - Fork 2
/
iris_classification.py
executable file
·59 lines (50 loc) · 1.56 KB
/
iris_classification.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/python3
from nicenet import NeuralNetwork
from nicenet import Dataset
from helpers import shuffle_array, split_arr
import numpy as np
inputs = 4
outputs = 3
network = NeuralNetwork(inputs, outputs, cost="ce")
network.add_layer(8, activation_function="sigmoid")
network.add_layer(8, activation_function="sigmoid")
network.compile(activation_function="softmax")
network.set_learning_rate(0.1)
dataset_handler = Dataset(inputs, outputs)
dataset_handler.make_dataset(
'./datasets/Iris/inputs.csv', './datasets/Iris/targets.csv')
data, size = dataset_handler.get_raw_data()
# data = dataset_handler.scale_data(data, size)
data = shuffle_array(data)
training, testing = split_arr(data, 3/4)
# print(len(training))
network.Train(training, len(training), epochs=50,
logging=False, epoch_logging=False)
network.evaluate()
network.epoch_vs_error()
network.export_model('iris_model.json')
correct = 0
total = 0
for sample in testing:
features = sample[0]
prediction = network.predict(features)
actual = sample[1]
p = np.argmax(prediction)
a = np.argmax(actual.T[0])
if p == a:
correct += 1
total += 1
print("Testing accuracy:", correct*100/total)
# new_network = NeuralNetwork.load_model('iris_model.json')
# correct = 0
# total = 0
# for sample in testing :
# features = sample[0]
# prediction = new_network.predict(features)
# actual = sample[1]
# p = np.argmax(prediction)
# a = np.argmax(actual.T[0])
# if p == a:
# correct += 1
# total += 1
# print("Testing accuracy:", correct*100/total)