-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
41 lines (29 loc) · 1.28 KB
/
utils.py
File metadata and controls
41 lines (29 loc) · 1.28 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
import numpy as np
import pandas as pd
def array_to_batch(data, batch_size):
num_batches = np.floor(len(data) / batch_size)
if len(data) % batch_size == 0:
batches = np.array_split(data, num_batches)
else:
batches = np.array_split(data[: -(len(data) % batch_size)], num_batches)
return np.array(batches)
def normalization(data):
data_normalize = data.copy()
cols = data_normalize.columns
i = data.shape[-1] - 2
data_normalize.loc[:, cols[i]] = (data.loc[:, cols[i]] - data.loc[:, cols[i]].min()) / (
data.loc[:, cols[i]].max() - data.loc[:, cols[i]].min())
# data_normalize.loc[:, cols[i]].apply(lambda x: x - x.mean() / x.std())
return data_normalize
def normalize(data):
data_normalize = data.copy()
cols = data_normalize.columns
for i in range(data.shape[-1]):
data_normalize.loc[:, cols[i]] = (data.loc[:, cols[i]] - data.loc[:, cols[i]].mean()) / data.loc[:, cols[i]].std()
# data_normalize.loc[:, cols[i]].apply(lambda x: x - x.mean() / x.std())
return data_normalize
def inverse_normalize(test_df, pred_y):
test_y_mean = test_df.loc[:, "Y"].mean()
test_y_std = test_df.loc[:, "Y"].std()
inverse_normalize_pred_y = pred_y * test_y_std + test_y_mean
return inverse_normalize_pred_y