-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataPreprocess.py
More file actions
68 lines (60 loc) · 1.77 KB
/
DataPreprocess.py
File metadata and controls
68 lines (60 loc) · 1.77 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
import numpy as np
# load the data from file
def LoadData(fileName):
fid = open(fileName)
lines = fid.readlines()
dataLoad = []
for line in lines:
lineSplit = line.strip().split()
dataLoad.append(list(map(float,lineSplit)))
return dataLoad
# divide the data into 10 lists by label
def DivideData(data):
data0 = []
data1 = []
data2 = []
data3 = []
data4 = []
data5 = []
data6 = []
data7 = []
data8 = []
data9 = []
for dataPoints in data:
if dataPoints[0]==0.0:
data0.append(dataPoints)
elif dataPoints[0]==1.0:
data1.append(dataPoints)
elif dataPoints[0]==2.0:
data2.append(dataPoints)
elif dataPoints[0]==3.0:
data3.append(dataPoints)
elif dataPoints[0]==4.0:
data4.append(dataPoints)
elif dataPoints[0]==5.0:
data5.append(dataPoints)
elif dataPoints[0]==6.0:
data6.append(dataPoints)
elif dataPoints[0]==7.0:
data7.append(dataPoints)
elif dataPoints[0]==8.0:
data8.append(dataPoints)
elif dataPoints[0]==9.0:
data9.append(dataPoints)
return [data0,data1,data2,data3,data4,data5,data6,data7,data8,data9]
# divide data with label 1 and 5 from all data
def GetOneFive(fileName):
data = LoadData(fileName)
# get the data with label 1 and 5
dataOneFive = []
for dataPoints in data:
if dataPoints[0]==1.0:
dataOneFive.append(dataPoints)
elif dataPoints[0]==5.0:
dataPoints[0]=0.0
dataOneFive.append(dataPoints)
# X is the data with label 1 and 5
# Y is the label
X = np.array(dataOneFive)[:,1:]
Y = np.array(dataOneFive)[:,0]
return X,Y