-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsavetonumpy.py
More file actions
executable file
·77 lines (58 loc) · 1.93 KB
/
savetonumpy.py
File metadata and controls
executable file
·77 lines (58 loc) · 1.93 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python2.7
import numpy as np
import pandas as pd
import pdb
import sys
training = pd.read_csv("data/training.csv")
test = pd.read_csv("data/test.csv")
print 0, len(training.columns)
#
# work on features
#
# lab_train = training.pop("Label")
# weight = training.pop("Weight")
lab_train = training["Label"]
weight = training["Weight"]
del training["Label"]
del training["Weight"]
# for col in training.columns:
# print u" " + col
print("test columns:")
print test.columns
lab_train.iloc[np.where(lab_train == "s")] = 1
lab_train.iloc[np.where(lab_train == "b")] = 0
y_train = lab_train.values
weight = weight.values
print 1, len(training.columns)
print("Feature matrix columns:")
print training.columns
del training["Label"]
X_train = training.values
X_test = test.values
print 2, X_train.shape
pdb.set_trace()
X_train = X_train.astype(np.float64)
X_test = X_test.astype(np.float64)
y_train = y_train.astype(np.float64)
weight = weight.astype(np.float64)
# print("X_train shape: {}".format(X_train.shape))
# print("Y_train shape: {}".format(y_train.shape))
print("X_train shape: {}".format(X_train.shape))
print("X_test shape: {}".format(X_test.shape))
print("Y_train shape: {}".format(y_train.shape))
print("Weight shape: {}".format(weight.shape))
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == "-s":
np.save("data/X_train.npy", X_train)
np.save("data/Y_train.npy", y_train)
print("Output written: X_train.npy, Y_train.npy")
print("X_train shape: {}".format(X_train.shape))
print("Y_train shape: {}".format(y_train.shape))
np.save("data/X_test.npy", X_test)
print("Output written: X_test.npy")
print("X_test shape: {}".format(X_test.shape))
np.save("data/weight.npy", weight)
print("Output written: weight.npy")
print("Weight shape: {}".format(weight.shape))
else:
print("---> No output, use -s flag to save")