-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
64 lines (50 loc) · 2.43 KB
/
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
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
60
61
62
63
64
from neuralnetwork import *
from aivalidation import *
from matplotlib import pyplot as plt
from settings import *
from sklearn.datasets import load_iris
np.random.seed(1) # It makes AI predictable
def main():
test(use_file, 0.6, learning_param)
test_iris(0.6, learning_param)
# tests neural network with given data file
def test(filename, coef, alpha):
# imports data from file
data, header = read_file(filename)
data = convertToNumpyArray(convertDataToFloat(data))
learn_data, test_data = two_subset_divide(data, coef)
perceptron = NeuralNetwork(learn_data, hidden_layer_size, output_layer_size, bias)
perceptron.train(era, alpha)
loss, score_right, score_rounded, predicted, actual = algorithm_validation(test_data, perceptron, (3, 9))
# print('Compare between predicted and original:')
#for i in range(len(predicted)):
#print(f'Predicted: {predicted[i]} Original: {actual[i]}')
print(f'Story of changes: {perceptron.errors}')
print(f'We missed about (loss): {loss} class, and we guessed right {score_right * 100}%')
print(f'If we rounded output, we guessed right {score_rounded * 100}%')
# print(f'Size of predicted set is: {len(predicted)}')
# print(f'Size of data is {len(data)}')
plt.plot(perceptron.errors)
plt.title('Neural Network errors')
plt.show()
# tests neural network with iris data set
def test_iris(coef, alpha):
data = load_iris(return_X_y=True)
data = np.concatenate((data[0], data[1][:, None]), axis=1)
learn_data, test_data = two_subset_divide(data, coef)
perceptron = NeuralNetwork(learn_data, hidden_layer_size, output_layer_size, bias)
perceptron.train(era, alpha)
loss, score_right, score_rounded, predicted, actual = algorithm_validation(test_data, perceptron, (0, 2))
# print('Compare between predicted and original:')
#for i in range(len(predicted)):
#print(f'Predicted: {predicted[i]} Original: {actual[i]}')
print(f'Story of changes: {perceptron.errors}')
print(f'We missed about (loss): {loss} class, and we guessed right {score_right * 100}%')
print(f'If we rounded output, we guessed right {score_rounded * 100}%')
# print(f'Size of predicted set is: {len(predicted)}')
# print(f'Size of data is {len(data)}')
plt.plot(perceptron.errors)
plt.title('Neural Network errors')
plt.show()
if __name__ == '__main__':
main()