-
Notifications
You must be signed in to change notification settings - Fork 19
/
load_data.py
140 lines (101 loc) · 5.49 KB
/
load_data.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
import pandas as pd
from sklearn.preprocessing import StandardScaler, MinMaxScaler
def load_data_FD001():
dir_path = './CMAPSSData/'
# define column names for easy indexing
index_names = ['unit_nr', 'time_cycles']
setting_names = ['setting_1', 'setting_2', 'setting_3']
sensor_names = ['s_{}'.format(i) for i in range(1, 22)]
col_names = index_names + setting_names + sensor_names
# read data
train_raw = pd.read_csv((dir_path + 'train_FD001.txt'), sep='\s+', header=None, names=col_names)
test_raw = pd.read_csv((dir_path + 'test_FD001.txt'), sep='\s+', header=None, names=col_names)
y_test = pd.read_csv((dir_path + 'RUL_FD001.txt'), sep='\s+', header=None, names=['RUL']).to_numpy()
grouped_by_unit = train_raw.groupby(by="unit_nr")
max_cycle = grouped_by_unit["time_cycles"].max().to_numpy()
grouped_by_unit_t = test_raw.groupby(by="unit_nr")
max_cycle_t = grouped_by_unit_t["time_cycles"].max().to_numpy()
# drop non-informative features, derived from EDA
drop_sensors = ['s_1', 's_5', 's_10', 's_16', 's_18', 's_19']
drop_labels = setting_names + drop_sensors
train_raw.drop(labels=drop_labels, axis=1, inplace=True)
test_raw.drop(labels=drop_labels, axis=1, inplace=True)
remaining_sensors = ['s_2', 's_3', 's_4', 's_6', 's_7', 's_8', 's_9',
's_11', 's_12', 's_13', 's_14', 's_15', 's_17', 's_20', 's_21']
return train_raw, test_raw, max_cycle, max_cycle_t, y_test
def load_data_FD002():
dir_path = './CMAPSSData/'
# define column names for easy indexing
index_names = ['unit_nr', 'time_cycles']
setting_names = ['setting_1', 'setting_2', 'setting_3']
sensor_names = ['s_{}'.format(i) for i in range(1, 22)]
col_names = index_names + setting_names + sensor_names
# read data
train_raw = pd.read_csv((dir_path + 'train_FD002.txt'), sep='\s+', header=None, names=col_names)
test_raw = pd.read_csv((dir_path + 'test_FD002.txt'), sep='\s+', header=None, names=col_names)
y_test = pd.read_csv((dir_path + 'RUL_FD002.txt'), sep='\s+', header=None, names=['RUL']).to_numpy()
grouped_by_unit = train_raw.groupby(by="unit_nr")
max_cycle = grouped_by_unit["time_cycles"].max().to_numpy()
grouped_by_unit_t = test_raw.groupby(by="unit_nr")
max_cycle_t = grouped_by_unit_t["time_cycles"].max().to_numpy()
# drop non-informative features, derived from EDA
# drop_sensors = ['s_1', 's_5', 's_10', 's_16', 's_18', 's_19']
drop_labels = setting_names
train_raw.drop(labels=drop_labels, axis=1, inplace=True)
test_raw.drop(labels=drop_labels, axis=1, inplace=True)
return train_raw, test_raw, max_cycle, max_cycle_t, y_test
def load_data_FD003():
dir_path = './CMAPSSData/'
# define column names for easy indexing
index_names = ['unit_nr', 'time_cycles']
setting_names = ['setting_1', 'setting_2', 'setting_3']
sensor_names = ['s_{}'.format(i) for i in range(1, 22)]
col_names = index_names + setting_names + sensor_names
# read data
train_raw = pd.read_csv((dir_path + 'train_FD003.txt'), sep='\s+', header=None, names=col_names)
test_raw = pd.read_csv((dir_path + 'test_FD003.txt'), sep='\s+', header=None, names=col_names)
y_test = pd.read_csv((dir_path + 'RUL_FD003.txt'), sep='\s+', header=None, names=['RUL']).to_numpy()
grouped_by_unit = train_raw.groupby(by="unit_nr")
max_cycle = grouped_by_unit["time_cycles"].max().to_numpy()
grouped_by_unit_t = test_raw.groupby(by="unit_nr")
max_cycle_t = grouped_by_unit_t["time_cycles"].max().to_numpy()
# drop non-informative features, derived from EDA
drop_sensors = ['s_1', 's_5', 's_10', 's_16', 's_18', 's_19']
drop_labels = setting_names + drop_sensors
train_raw.drop(labels=drop_labels, axis=1, inplace=True)
test_raw.drop(labels=drop_labels, axis=1, inplace=True)
return train_raw, test_raw, max_cycle, max_cycle_t, y_test
def load_data_FD004():
dir_path = './CMAPSSData/'
# define column names for easy indexing
index_names = ['unit_nr', 'time_cycles']
setting_names = ['setting_1', 'setting_2', 'setting_3']
sensor_names = ['s_{}'.format(i) for i in range(1, 22)]
col_names = index_names + setting_names + sensor_names
# read data
train_raw = pd.read_csv((dir_path + 'train_FD004.txt'), sep='\s+', header=None, names=col_names)
test_raw = pd.read_csv((dir_path + 'test_FD004.txt'), sep='\s+', header=None, names=col_names)
y_test = pd.read_csv((dir_path + 'RUL_FD004.txt'), sep='\s+', header=None, names=['RUL']).to_numpy()
grouped_by_unit = train_raw.groupby(by="unit_nr")
max_cycle = grouped_by_unit["time_cycles"].max().to_numpy()
grouped_by_unit_t = test_raw.groupby(by="unit_nr")
max_cycle_t = grouped_by_unit_t["time_cycles"].max().to_numpy()
# drop non-informative features, derived from EDA
# drop_sensors = ['s_1', 's_5', 's_10', 's_16', 's_18', 's_19']
drop_labels = setting_names
train_raw.drop(labels=drop_labels, axis=1, inplace=True)
test_raw.drop(labels=drop_labels, axis=1, inplace=True)
return train_raw, test_raw, max_cycle, max_cycle_t, y_test
def get_info(train_raw, test_raw):
mm = MinMaxScaler()
ss = StandardScaler()
X = train_raw.iloc[:, 2:]
idx = train_raw.iloc[:, 0:2].to_numpy()
X_ss = ss.fit_transform(X)
X_t = test_raw.iloc[:, 2:]
idx_t = test_raw.iloc[:, 0:2].to_numpy()
Xt_ss = ss.fit_transform(X_t)
nf = X_ss.shape[1]
ns = X_ss.shape[0]
ns_t = Xt_ss.shape[0]
return X_ss, idx, Xt_ss, idx_t, nf, ns, ns_t