def test_scaler_minmax_1D(self): ones = numpy.ones(10).reshape(1, -1) for i in range(1, 5): scaler = MinMaxScaler() data = numpy.hstack([ones * i, ones * -i]) # Verify that normalization of data works as expected norm = scaler.fit(data).transform(data) self.assertEqual(norm[0].min(), 0) self.assertEqual(norm[0].max(), 1)
def test_scaler_minmax(self): ones = numpy.ones(10) for i in range(1, 5): scaler = MinMaxScaler() data = numpy.concatenate([ones * i, ones * -i]) # Verify that normalization of data works as expected norm = scaler.fit(data).transform(data) self.assertEqual(norm.min(), 0) self.assertEqual(norm.max(), 1)
def test_scaler_minmax_inverse(self): ones = numpy.ones(10) for i in range(1, 5): scaler = MinMaxScaler() data = numpy.concatenate([ones * i, ones * -i]) norm = scaler.fit(data).transform(data) self.assertEqual(norm.min(), 0) self.assertEqual(norm.max(), 1) norm_inv = scaler.inverse_transform(norm) self.assertListEqual(data.tolist(), norm_inv.tolist())
def test_scaler_minmax_2D_batches(self): ones = numpy.ones(20).reshape(2, -1) for i in range(1, 5): scaler = MinMaxScaler(columns=[0, 1]) scaler = scaler.fit(ones * i) scaler = scaler.fit(ones * -i) # Verify that normalization of data works as expected norm = scaler.transform(numpy.hstack([ones * i, ones * -i])) self.assertEqual(norm[0].min(), 0) self.assertEqual(norm[1].min(), 0) self.assertEqual(norm[0].max(), 1) self.assertEqual(norm[1].max(), 1)
def test_scaler_minmax_3D(self): # Single column with 10 samples of an 8x8 matrix ones = numpy.ones((10, 8, 8)) for i in range(1, 5): scaler = MinMaxScaler() # Wrap the matrix into an array to delineate single column data = [numpy.vstack([ones * i, ones * -i])] # Verify that normalization of data works as expected norm = scaler.fit(data).transform(data) self.assertEqual(norm[0].min(), 0) self.assertEqual(norm[0].max(), 1)