2

I'm curious about any preference of using tf.keras.utils.normalize vs the way we usually normalize a series, subtracting mean and dividing by standard deviation:

import tensorflow as tf
import numpy as np

series = np.random.random(10) + 10 * np.sin(np.random.random(1))
mean = np.mean(series)
std = np.std(series)

(series - mean) / std

tf.keras.utils.normalize(series)

Is there any pros/cons for either method?

tf normalize in [0,1] range, but we get values in [-1,1] range using the other method.

Mehdi Zare
  • 1,221
  • 1
  • 16
  • 32

1 Answers1

1

tf.keras.utils.normalize uses the algorithm described here., so it just makes the data along the specified axis a unit vector with respect to your favorite lp norm. Whether this is preferable to sklearn.StandardScaler() depends on the problem. For many time series problems, you want to detrend them, so make the mean 0., so StandardScaler is appropriate. If you want the inputs reasonably similarly scaled, both methods are equivalent, more or less.

Igor Rivin
  • 4,632
  • 2
  • 23
  • 35