-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfit_SpAM.py
82 lines (70 loc) · 1.84 KB
/
fit_SpAM.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
78
79
80
81
import sys
import os
import random
import argparse
import logging
import pickle
import subprocess
import numpy as np
from common import write_data_pkl_to_csv
def parse_args():
''' parse command line arguments '''
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--seed',
type=int,
help='seed',
default=1)
parser.add_argument('--kfold',
type=int,
default=3)
parser.add_argument('--data-file',
type=str,
default="_output/data.pkl")
parser.add_argument('--out-file',
type=str,
default="_output/out.csv")
parser.add_argument('--data-classes',
type=int,
default=0)
parser.add_argument('--num-splines',
type=int,
default=8)
parser.add_argument('--scratch',
type=str,
default="_output/scratch")
args = parser.parse_args()
return args
def fit_spam(
args,
train_file,
test_file):
cmd = [
'Rscript',
'../R/fit_SpAM.R',
train_file,
test_file,
args.out_file,
args.data_classes,
args.seed,
args.kfold,
args.num_splines,
]
cmd = list(map(str, cmd))
print("Calling:", " ".join(cmd))
res = subprocess.call(cmd)
# Check that process complete successfully
assert res == 0
def main(args=sys.argv[1:]):
args = parse_args()
randnum = random.randint(1, 100000)
train_file_name = os.path.join(args.scratch, "train%d" % randnum)
test_file_name = os.path.join(args.scratch, "test%d" % randnum)
write_data_pkl_to_csv(
args.data_file,
train_file_name,
test_file_name)
fit_spam(args, train_file_name, test_file_name)
os.remove(train_file_name)
os.remove(test_file_name)
if __name__ == "__main__":
main(sys.argv[1:])