Search code examples
pythonnumpykerasstandardized

Standardizing numpy array in Keras


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.


Solution

  • 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.