-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormalization.py
More file actions
56 lines (35 loc) · 1.17 KB
/
Copy pathnormalization.py
File metadata and controls
56 lines (35 loc) · 1.17 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
"""Different normalizations"""
import numpy as np
def normalization_01(x):
"""To normalize the feature x within range [0,1]
Args:
x (array): feature
Returns:
array: Normalized feature
"""
normalized_x = [round(((x_i) - min(x)) / (max(x) - min(x)), 4) for x_i in x]
return normalized_x
def normalization_11(x):
"""To normalize the feature x within range [-1,1]
Args:
x (array): feature
Returns:
array: Normalized feature
"""
normalized_x = [
round((2 * (x_i) - min(x) - max(x)) / (max(x) - min(x)), 4) for x_i in x
]
return normalized_x
def mean_normalization(x):
"""To normalize the feature x within range [-1,1]
Args:
x (array): feature
Returns:
array: Normalized feature
"""
normalized_x = [round(((x_i) - np.mean(x)) / (max(x) - min(x)), 4) for x_i in x]
return normalized_x
x = [100, 120, 200, 4563, 23, 56, 788, 1000, 3400, 40, 400, 2500, 4000, 1700]
print(f"Normalized x in range[0,1] : {normalization_01(x)}")
print(f"Normalized x in range[0,1] : {normalization_11(x)}")
print(f"Normalized x in range[0,1] : {mean_normalization(x)}")