-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpost_preprocessing.py
More file actions
64 lines (35 loc) · 1.56 KB
/
Copy pathpost_preprocessing.py
File metadata and controls
64 lines (35 loc) · 1.56 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
def post_preprocessing (data_name, train = False):
import pandas as pd
import numpy as np
from sklearn import preprocessing
raw = pd.read_csv(data_name)
if train == True:
sh_train = raw.copy().sample(frac = 1).reset_index(drop = True)
rw_tr_in = sh_train.drop("sales", axis = 1)
rw_tr_out = sh_train.filter(["sales"], axis = 1)
input_samples = rw_tr_in.copy()
target_samples = rw_tr_out.copy()
n_train = int(0.8 * len(rw_tr_in))
b_tr_in = input_samples[:n_train]
b_tr_out = target_samples[:n_train]
b_val_in = input_samples[n_train:]
b_val_out = target_samples[n_train:]
# IDS
tr_ID = b_tr_in.filter(["ID"], axis = 1)
val_ID = b_val_in.filter(["ID"], axis = 1)
# FEATURES
s_tr_in = b_tr_in.drop("ID", axis = 1)
s_val_in = b_val_in.drop("ID", axis = 1)
tr_in = preprocessing.scale(s_tr_in)
tr_out = preprocessing.scale(b_tr_out)
val_in = preprocessing.scale(s_val_in)
val_out = preprocessing.scale(b_val_out)
np.savez ("train", id = tr_ID, inputs = tr_in, targets = tr_out)
np.savez ("val", id = val_ID, inputs = val_in, targets = val_out)
if test == False:
test_ID = raw.filter(["ID"], axis = 1)
rw_test_in = raw.drop(["ID"], axis = 1)
test_ID = raw.filter(["ID"], axis = 1)
s_test = rw_test_in.drop("ID", axis = 1)
test = preprocessing.scale(s_test)
np.savez ("test", id = test_ID, inputs = test)