-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_data.py
More file actions
58 lines (51 loc) · 1.63 KB
/
process_data.py
File metadata and controls
58 lines (51 loc) · 1.63 KB
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
import random
def get_data():
file = open('data.txt', 'r')
file_data = file.read().split("\n")
data_bunch = [i for i in file_data]
data_bunch.remove(data_bunch[-1])
random.shuffle(data_bunch)
pre_processed_features = []
pre_processed_labels = []
for j in data_bunch:
d = j.split(",")
t_d = [i for i in d]
t_d.remove(t_d[-1])
pre_processed_features.append(t_d)
pre_processed_labels.append(d[-1])
processed_features = pre_processed_features
processed_labels = []
for label in pre_processed_labels:
label = label.replace("Iris-versicolor", "versicolor")
label = label.replace("Iris-setosa", "setosa")
processed_labels.append(label)
data = (processed_features, processed_labels)
return data
def process_data(pre_data):
train_data = []
test_data = []
for d in pre_data[0]:
sub_data = []
for entry in d:
sub_data.append(float(entry))
train_data.append(sub_data)
for d in pre_data[1]:
if d == "setosa":
test_data.append(1)
elif d == "versicolor":
test_data.append(0)
return (train_data, test_data)
def process_data_2(pre_data):
train_data = []
test_data = []
for d in pre_data[0]:
sub_data = []
for entry in d:
sub_data.append(float(entry))
train_data.append(sub_data)
for d in pre_data[1]:
if d == "setosa":
test_data.append(np.array([1, 0]).reshape(2,1))
elif d == "versicolor":
test_data.append(np.array([0, 1]).reshape(2, 1))
return (train_data, test_data)