-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnormalizer.py
43 lines (30 loc) · 1009 Bytes
/
normalizer.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
import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler, StandardScaler
def decimalNormalize(x):
return (np.array(x) / 10**np.ceil(np.log10(max(x))))
def decimalNormalizeOver(x,maximum):
X = (np.array(x) / 10 ** np.ceil(np.log10(maximum)))
X[X > 1.0] = 1.0 # limit top
return X
def decimalDenormalize (x,maximum):
return (np.array(x)*(10**np.ceil(np.log10(maximum))))
def minMaxNormalize(x):
scaler = MinMaxScaler(feature_range=(-1, 1))
scaler.fit(x)
return scaler.transform(x), scaler
def minMaxNormalizeOver(x, scaler):
X = scaler.transform(x)
X[X>1.0] = 1.0 # limit top
X[X<-1.0] = -1.0 #limit bottom
return X
def minMaxDenormalize(x, scaler):
return scaler.inverse_transform(x)
def zNormalize(x):
scaler = StandardScaler()
scaler.fit(x)
return scaler.transform(x), scaler
def zNormalizeOver(x, scaler):
return scaler.transform(x)
def zDenormalize(x, scaler):
return scaler.inverse_transform(x)