0

I used the tensorflow tf.keras.metrics.MeanSquaredError() metric to evaluate the mean squared error between two numpy arrays. But each time I call mse() it give a different result.

a = np.random.random(size=(100,2000))
b = np.random.random(size=(100,2000))

for i in range(100):
    v = mse(a, b).numpy()
    plt.scatter(i,v)
    print(v)

where I had previously defined mse = tf.keras.metrics.MeanSquaredError() Here is the Output. Any idea what is going wrong?

Aks
  • 1
  • Is your code missing the indices `a[i]` and `b[i]` in the MSE calculation or is that what you want? Could this issue be related to not seeding your random number generator? In general, the MSE should be the same if you input the same data. Now you'd need to check whether you actually have the same inputs. – André Aug 31 '22 at 12:28
  • Can you give more details? I was not able to reproduce it on my environment. – JumbaMumba Aug 31 '22 at 13:31
  • Please provide enough code so others can better understand or reproduce the problem. – Community Aug 31 '22 at 18:27

1 Answers1

1

np.random.random generates random data every run. So, your code should result in different mse, shouldn't it?

run 1: [0.87148841 0.50221413 0.49858526 ... 0.22311888 0.71320089 0.36298912]

Run 2: [0.14941241 0.78560523 0.62436783 ... 0.1865485 0.2730567 0.49300401]

band
  • 129
  • 7