-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbalance.py
42 lines (31 loc) · 883 Bytes
/
balance.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
# balance_data.py
import numpy as np
import pandas as pd
from collections import Counter
from random import shuffle
train_data = np.load('training_data.npy')
df = pd.DataFrame(train_data)
print(df.head())
print(Counter(df[1].apply(str)))
forwards = []
mouse = []
nm = []
shuffle(train_data)
for data in train_data:
img = data[0]
choice = data[1]
if choice == [1,0,0]:
forwards.append([img,choice])
elif choice == [0,0,1]:
mouse.append([img,choice])
elif choice == [0,1,0]:
mouse.append([img,choice])
elif choice == [0,0,0]:
nm.append([img,choice])
else:
print('no matches')
forwards = forwards[:len(mouse)][:len(nm)]
mouse = mouse[:len(forwards)][:len(nm)]
final_data = forwards + nm + mouse
shuffle(final_data)
np.save('training_data_balanced.npy', final_data)