Standardizing numpy array in Keras

1

After I trained my model in Keras, it is time for prediction, so I am using some data in order to check my model on. However, the trained model is standardized before training (Very different range of values).

So in order to predict on some data, I should standardize it too:

packet = numpy.array([[3232235781, 3232235779, 6, 128, 2, 1, 0, 524288, 56783, 502, 0, 0x00000010, 0, 0, 61, 0, 0, 0]])
scaler = StandardScaler().fit(packet)
rescaled_packet = scaler.transform(packet)
print(rescaled_packet) 

the output is always 0's: [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

Does any one knows how to standardize numpy array?

Note that a warning error is appearing saying that DataConversionWarning: Data with input dtype int64 was converted to float64 by StandardScaler. warnings.warn(msg, _DataConversionWarning) But I do not think that this is the problem.

python
numpy
keras
standardized
asked on Stack Overflow May 22, 2017 by Ahmad Hijazi

2 Answers

1

This actually comes from the fact that you have only one example in your dataset. When you call fit on a table with one example - a mean of each column is computed - but in case when you have only one number in each column - this mean is equal to first (and only) row. That's why you are obtaining a vector of 0's.

answered on Stack Overflow May 22, 2017 by Marcin Możejko
0
import numpy as np

a = np.array([10,1,-4,35,26])
a_stand = (a - a.mean()*np.ones(len(a)))/(a.std())

It is what you want ?

answered on Stack Overflow May 22, 2017 by Aaron Aben Danan • edited May 22, 2017 by Thomas Ayoub

User contributions licensed under CC BY-SA 3.0