Search code examples
tensorflowkerasneural-networkdata-science

Why predicted values are towards center?


It looks like most predicted values are close to 0.5. How can the predicted values follow closer the original values?

normalizer = layers.Normalization()
normalizer.adapt(np.array(X_train))

model = keras.Sequential([
        normalizer,
        layers.Dense(8, activation='relu'),
        layers.Dense(1, activation='linear'),
        layers.Normalization()
    ])

enter image description here enter image description here


Solution

  • There might be many issues here, but definitely you cannot normalize data at the output. You are literally saying "on average, I am expecting my output to be 0 and have unit variance". This makes sense iff your target is a standard, normalised Gaussian, but from the plot you can tell clearly it is not. Normalising inputs, or internal activations is fine, as there is always the final layer to apply final affine mapping. But if you do so at the end of the network, you are just making it impossible to learn most targets/signals.

    Once this is solved, a network with 8 hidden neurons is extremely tiny and there is absolutely no guarantee it can learn anything, your training loss is very far from 0, you should make it much, much more expressive, and try to get your training to 0, if you can't do this - you have a bug somewhere else in the code (or the model is not expressive enough).