-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wrapper.py
More file actions
executable file
·43 lines (33 loc) · 941 Bytes
/
Copy pathtest_wrapper.py
File metadata and controls
executable file
·43 lines (33 loc) · 941 Bytes
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
#!/usr/bin/env python
import random
import os
PERCENT_TEST = .20
#need to chop up affinities.dump
length = 0
#we want to know how big the file is
with open("publicvotes-20101018_affinities.dump") as f:
for line in f:
length += 1
test_set_size = int(length*PERCENT_TEST)
test_set_idexes = random.sample(range(length), test_set_size)
test_set_dict = {}
for index in test_set_idexes:
test_set_dict[index] = 1
training_set = []
test_set = []
i = 0
with open("publicvotes-20101018_affinities.dump") as f:
for line in f:
if i in test_set_dict:
test_set.append(line)
else:
training_set.append(line)
i += 1
with open("test_dataset",'w') as f:
for line in test_set:
f.write(line)
with open("training_dataset",'w') as f:
for line in training_set:
f.write(line)
os.system("cat training_dataset | ./srrecs.py \"write_matrix('affinities.cm', 'affinities.clabel', 'affinities.rlabel')\"")
os.system("R -f ./srrecs.r")