-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_normalizationScaler.py
31 lines (25 loc) · 1.33 KB
/
test_normalizationScaler.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
from unittest import TestCase
from utils import NormalizationScaler, MinMaxScaler
import numpy
from numpy.testing import assert_array_almost_equal
class TestNormalizationScaler(TestCase):
def test_normalization(self):
normal = NormalizationScaler()
features = [[3, 4], [1, -1], [0, 0]]
assert_array_almost_equal(numpy.array([[0.6, 0.8], [0.707107, -0.707107], [0, 0]]), numpy.array(normal(features)))
assert_array_almost_equal(numpy.array([[0.6, 0.8], [0.707107, -0.707107], [0, 0]]), numpy.array(normal(features)))
def test_min_max_scalar(self):
mim_max = MinMaxScaler()
train_features = [[0, 10], [2, 0]]
test_features = [[20, 1]]
train_features_scaled = mim_max(train_features)
# now train_features_scaled should be [[0, 1], [1, 0]]
self.assertListEqual([[0, 1], [1, 0]], train_features_scaled)
test_features_scaled = mim_max(test_features)
# now test_features_scaled should be [[10, 0.1]]
self.assertListEqual([[10, 0.1]], test_features_scaled)
new_scaler = MinMaxScaler() # creating a new scaler
_ = new_scaler([[1, 1], [0, 0]]) # new trainfeatures
test_features_scaled = new_scaler(test_features)
# now test_features_scaled should be [[20, 1]]
self.assertListEqual([[20, 1]], test_features_scaled)