forked from myay/TREAM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepareExpData.py
160 lines (144 loc) · 6.96 KB
/
prepareExpData.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from sklearn.model_selection import train_test_split
from loadData import readFileMNIST, readFileAdult, readFileSensorless, readFileWinequality, readFileWine, readFileTicTacToe, readFileOccupancy, readFileSpamBase, readFileWearable, readFileLetter
from sklearn.datasets import load_iris, fetch_olivetti_faces, fetch_covtype
from Utils import quantize_data
import numpy as np
def getData(dataset, this_path, nr_bits_split, nr_bits_feature, random_state):
X_train, y_train, X_test, y_test = None, None, None, None
if dataset == "MNIST":
# nr_bits_split = 8
# nr_bits_feature = 8
dataset_train_path = "/data/mnist/train.csv"
dataset_test_path = "/data/mnist/test.csv"
train_path = this_path + dataset_train_path
test_path = this_path + dataset_test_path
X_train, y_train = readFileMNIST(train_path)
X_test, y_test = readFileMNIST(test_path)
if dataset == "IRIS":
# nr_bits_split = 7
# nr_bits_feature = 7
dataset_train_path = "/sklearn"
dataset_test_path = "/sklearn"
train_path = this_path + dataset_train_path
test_path = this_path + dataset_test_path
iris = load_iris()
X, y = iris.data, iris.target
X *= 10
X = X.astype(np.uint8)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=random_state)
# with open('output.txt', 'a') as f:
# f.write(np.array2string(X))
if dataset == "ADULT":
# nr_bits_split = 8 # int, use 32 for fp
# nr_bits_feature = 8 # int, use 32 for fp
dataset_path = "data/adult/adult.data"
X, y = readFileAdult(dataset_path)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
# comment out quantization, if it is not desired
X_train = quantize_data(X_train, nr_bits_feature)
X_test = quantize_data(X_test, nr_bits_feature)
if dataset == "SENSORLESS":
# nr_bits_split = 32 # floating point
# nr_bits_feature = 32 # floating point
dataset_path = "data/sensorless-drive/Sensorless_drive_diagnosis.txt"
X, y = readFileSensorless(dataset_path)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
if dataset == "WINEQUALITY":
# nr_bits_split = 32 # floating point
# nr_bits_feature = 32 # floating point
dataset_path = "data/wine-quality/"
X, y = readFileWinequality(dataset_path)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
if dataset == "WINE":
dataset_path = "data/wine/"
X, y = readFileWine(dataset_path)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
if dataset == "TIC-TAC-TOE":
dataset_path = "data/tic-tac-toe/"
X, y = readFileTicTacToe(dataset_path)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
if dataset == "OCCUPANCY":
dataset_path = "data/occupancy/"
X, y = readFileOccupancy(dataset_path)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
if dataset == "OLIVETTI":
# nr_bits_split = 8
# nr_bits_feature = 8
dataset_train_path = "/sklearn"
dataset_test_path = "/sklearn"
train_path = this_path + dataset_train_path
test_path = this_path + dataset_test_path
X, y = fetch_olivetti_faces(shuffle=True, random_state=random_state, download_if_missing=True, return_X_y=True)
X = np.array(X*255).astype(np.uint8) # use unsigned ints
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=random_state)
if dataset == "COVTYPE":
# nr_bits_split = 8
# nr_bits_feature = 8
dataset_train_path = "/sklearn"
dataset_test_path = "/sklearn"
train_path = this_path + dataset_train_path
test_path = this_path + dataset_test_path
X, y = fetch_covtype("data/covtype/", shuffle=True, random_state=random_state, download_if_missing=True, return_X_y=True)
# X = np.array(X).astype(np.uint8) # use unsigned ints
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=random_state)
# X_train = quantize_data(X_train, nr_bits_feature)
# X_test = quantize_data(X_test, nr_bits_feature)
if dataset == "SPAMBASE":
# nr_bits_split = 16
# nr_bits_feature = 16
dataset_path = "data/spambase/spambase.data"
X, y = readFileSpamBase(dataset_path)
# print("ma", X.max(), X.min())
# X = np.array(X).astype(np.uint8)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
X_train = quantize_data(X_train, nr_bits_feature)
X_test = quantize_data(X_test, nr_bits_feature)
if dataset == "WEARABLE":
# nr_bits_split = 16
# nr_bits_feature = 16
dataset_path = "data/wearable/dataset.csv"
X, y = readFileWearable(dataset_path)
# print("ma", X.max(), X.min())
# X = np.array(X).astype(np.uint8)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
X_train = quantize_data(X_train, nr_bits_feature)
X_test = quantize_data(X_test, nr_bits_feature)
if dataset == "LETTER":
# nr_bits_split = 8
# nr_bits_feature = 8
dataset_path = "data/letter/letter-recognition.data"
X, y = readFileLetter(dataset_path)
# print("ma", X.max(), X.min())
# X = np.array(X).astype(np.uint8)
# rint = np.random.randint(low=1, high=100)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.33, random_state=random_state)
X_train = quantize_data(X_train, nr_bits_feature)
X_test = quantize_data(X_test, nr_bits_feature)
if dataset == "WEATHERAUS":
# nr_bits_split = 8
# nr_bits_feature = 8
dataset_train_path = "/data/weatheraus/train.csv"
dataset_test_path = "/data/weatheraus/test.csv"
train_path = this_path + dataset_train_path
test_path = this_path + dataset_test_path
X_train, y_train = readFileMNIST(train_path)
X_test, y_test = readFileMNIST(test_path)
print("hey")
return X_train, y_train, X_test, y_test