-
Notifications
You must be signed in to change notification settings - Fork 1
/
preprocessing.py
51 lines (33 loc) · 1.17 KB
/
preprocessing.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
"""
"""
import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler, PolynomialFeatures
import pdb
def normalize(X_train, X_valid, X_test, normalizer='StandardScaler'):
"""
Normalizing the training, validation and test sets.
"""
if normalizer == 'StandardScaler':
norm = StandardScaler()
elif normalizer == 'MinMaxScaler':
norm = MinMaxScaler()
else:
raise Exception('Normalizer not supported')
X_train = np.log(1+X_train)
X_valid = np.log(1+X_valid)
X_test = np.log(1+X_test)
norm.fit(np.vstack((X_train, X_valid, X_test)))
X_train = norm.transform(X_train)
X_valid = norm.transform(X_valid)
X_test = norm.transform(X_test)
return X_train, X_valid, X_test
#def feature_engineering(train, test, degree=2,
# interaction_only=True):
# """
# """
# pef = PolynomialFeatures(degree=degree, interaction_only=interaction_only,
# include_bias=False)
# X_train = pef.fit_transform(train)
# X_test = pef.fit_transform(train)
#
# return X_train, X_test