-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.py
38 lines (30 loc) · 974 Bytes
/
data.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
import csv
import random
def load_csv(filename):
lines = []
with open(filename) as csvfile:
reader = csv.DictReader(csvfile)
for line in reader:
lines.append(line)
return lines
def load_adult_data():
return load_csv("adult.data")
# Note: Possibly use different data for training and validation to get a more accurate result,
# but remember that in the last part your model will be trained on the full training data
# load_adult_data() and be tested on a test dataset you don't have access to.
def split_data(train,val):
data = load_adult_data()
random.shuffle(data)
length = len(data)
if train == 1:
num = int(length*0.75)
return data[:num]
else:
num = length-int(length*0.75)
return data[num:]
def load_adult_train_data():
# return load_adult_data()
return split_data(1,0)
def load_adult_valid_data():
# return load_adult_data()
return split_data(0,1)