-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogreg_train.py
77 lines (65 loc) · 1.97 KB
/
logreg_train.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
65
66
67
68
69
70
71
72
73
74
75
76
77
from os import removedirs
from numpy import NaN
from numpy.lib.function_base import append
from libs.lib_neuron import neuron
from libs.dataset_reader import *
import matplotlib.pyplot as plt
# Extract data
header, data, raw_header, raw_data = open_dataset("./datasets/dataset_train.csv")
house_set = raw_data[:, 1]
astronomy_set = data[:, 1]
herbology_set = data[:, 2]
ravenclaw_set = []
slytherin_set = []
gryffindor_set = []
hufflepuff_set = []
# Format data
mask = []
mask_a = ~np.isnan(herbology_set)
mask_b = ~np.isnan(astronomy_set)
for i in range(len(mask_a)):
if (not mask_a[i] or not mask_b[i]):
mask.append(False)
else:
mask.append(True)
herbology_set = herbology_set[np.where(mask)]
astronomy_set = astronomy_set[np.where(mask)]
house_set = house_set[np.where(mask)]
# Fill result array
for i in house_set:
if i == "Ravenclaw":
ravenclaw_set.append(1)
slytherin_set.append(0)
gryffindor_set.append(0)
hufflepuff_set.append(0)
elif i == "Slytherin":
ravenclaw_set.append(0)
slytherin_set.append(1)
gryffindor_set.append(0)
hufflepuff_set.append(0)
elif i == "Gryffindor":
ravenclaw_set.append(0)
slytherin_set.append(0)
gryffindor_set.append(1)
hufflepuff_set.append(0)
elif i == "Hufflepuff":
ravenclaw_set.append(0)
slytherin_set.append(0)
gryffindor_set.append(0)
hufflepuff_set.append(1)
data = []
for i in range(len(astronomy_set)):
data.append([astronomy_set[i], herbology_set[i]])
data = np.array(data)
# Create neurons
neurons = []
neurons.append(neuron("ravenclaw", data, ravenclaw_set))
neurons.append(neuron("slytherin", data, slytherin_set))
neurons.append(neuron("gryffindor", data, gryffindor_set))
neurons.append(neuron("hufflepuff", data, hufflepuff_set))
for i in neurons:
i.plot_prediction()
i.plot_data()
# i.gradient_descent(200000, 0.01, progression=True)
# i.plot_history()
i.debug()