Answers.Body: <p>The model seems to train just fine (when measured by the MSE loss), accuracy metric is only relevant when the prediction is a true / false type.</p>
  <p>Arguably the network's structure isn't ideal for this problem, but that is beside the point.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T18:29:18.933Z
Answers.Text: isn't there still accuracy for the error? from the real result
Answers.UserDisplayName: Tobi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T18:55:29.467Z
Answers.Text: it doens't work. I tested with `print([(x, y[0]) for x,y in zip( y_val, model.predict(x_val))])` after 200 epochs and the results seem random, compared to the `y_val`
Answers.UserDisplayName: Tobi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T20:55:14.943Z
Answers.Text: After 100 epochs my code says `((model.predict(x_val) - y_val)**2).mean()` is 0.063620539. And the scatter plot looks good as well, correlation coefficient is 0.99984668648.
Answers.UserDisplayName: NikoNyrh
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T23:25:39.627Z
Answers.Text: `[(1.249716031816869, 0.32068107), (1.1568286658676914, 0.31521273), (1.3370053550792722, 0.33378834), (1.1397021505376013, 0.23554398), (1.1691912669776516, 0.30106655), (1.0633291121420687, 0.28948098), (0.849716930324254, 0.17947169), (1.012984152099238, 0.2649205), (1.018326969664438, 0.24658701)]` look, there's no correlation. The MSE isn't relative to anything so is effectively meaningless
Answers.UserDisplayName: Tobi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T23:38:19.900Z
Answers.Text: https://i.imgur.com/YJthW6Y.png
Answers.UserDisplayName: Tobi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T23:40:15.567Z
Answers.Text: https://i.imgur.com/oqU11l8.png
Answers.UserDisplayName: Tobi
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-09T15:52:07.530Z
Answers.LastActivityDate: 2022-01-09T15:52:07.530Z
Answers.UserDisplayName: NikoNyrh
Body: <p>I've been trying to figure out why this model won't train (the accuracy stays at 0).</p>
  <pre><code>frame_size = 2
  sequence_length = 5
  input_shape = (sequence_length, frame_size)
  
  
  def label_x(x: np.array):
      return np.average([np.sum(frame) for frame in x])
  
  
  def build_training_set(count: int):
      xs = np.random.rand(count, *input_shape)
      return xs, (np.array([label_x(x) for x in xs]))
  
  
  assert 12.4 == label_x([[1, 2], [5, 7], [12, 2], [21, 1], [5, 6]])
  
  train_count = 10000
  validate_count = int(train_count / 10)
  
  input = Input(shape=input_shape)
  hidden_1 = Dense(20, activation='relu')(input)
  rnn = LSTM(20)(hidden_1)
  output = Dense(1)(rnn)
  model = Model(inputs=input, outputs=[output])
  
  model.compile(
      optimizer=keras.optimizers.RMSprop(),  # Optimizer
      # Loss function to minimize
      loss=&quot;mse&quot;,
      # List of metrics to monitor
      metrics=[&quot;accuracy&quot;],
  )
  print(model.summary())
  
  x_train, y_train = build_training_set(train_count)
  x_val, y_val = build_training_set(validate_count)
  history = model.fit(
      x_train,
      y_train,
      batch_size=64,
      epochs=200,
      validation_data=(x_val, y_val),
  )
  </code></pre>
  <p>Anyone have an idea?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-09T15:16:58.983Z
Comments.Text: The model is only half of the problem.  You haven't given us any idea what the training dataset is or what you expect the network to be able to do.  You also do not tell us what steps you have *already* taken to figure out what's happening.
Comments.UserDisplayName: David Hoelzer
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-01-09T15:27:51.033Z
Comments.Text: @DavidHoelzer I'm trying to train the model to sum up each time step of the sample, and the average the result of sum of each timestep (see the `label_x` function). I want to do this using an RNN layer. I've tried changing the activation functions, the loss function and the optimisers, but nothing seems to be working. I'm not sure if I'm missing something trivial or not
Comments.UserDisplayName: Tobi
Tags: <recurrent-neural-networks><tensorflow>
Title: My accuracy wont improve in tensorflow
UserDisplayName: Tobi
ThreadText: # My accuracy wont improve in tensorflow
  
  (Asked by: username_0 on 2022-01-09)
  
  I've been trying to figure out why this model won't train (the accuracy stays at 0).
  
  ```
  frame_size = 2
  sequence_length = 5
  input_shape = (sequence_length, frame_size)
  
  def label_x(x: np.array):
      return np.average([np.sum(frame) for frame in x])
  
  def build_training_set(count: int):
      xs = np.random.rand(count, *input_shape)
      return xs, (np.array([label_x(x) for x in xs]))
  
  assert 12.4 == label_x([[1, 2], [5, 7], [12, 2], [21, 1], [5, 6]])
  
  train_count = 10000
  validate_count = int(train_count / 10)
  
  input = Input(shape=input_shape)
  hidden_1 = Dense(20, activation='relu')(input)
  rnn = LSTM(20)(hidden_1)
  output = Dense(1)(rnn)
  model = Model(inputs=input, outputs=[output])
  
  model.compile(
      optimizer=keras.optimizers.RMSprop(),  # Optimizer
      # Loss function to minimize
      loss="mse",
      # List of metrics to monitor
      metrics=["accuracy"],
  )
  print(model.summary())
  
  x_train, y_train = build_training_set(train_count)
  x_val, y_val = build_training_set(validate_count)
  history = model.fit(
      x_train,
      y_train,
      batch_size=64,
      epochs=200,
      validation_data=(x_val, y_val),
  )
  
  ```
  
  Anyone have an idea?
  
  **Tags:** recurrent-neural-networks, tensorflow
  
  > **Comments:**
  > **username_1**: The model is only half of the problem.  You haven't given us any idea what the training dataset is or what you expect the network to be able to do.  You also do not tell us what steps you have *already* taken to figure out what's happening.  
  > **username_0**: @username_1 I'm trying to train the model to sum up each time step of the sample, and the average the result of sum of each timestep (see the `label_x` function). I want to do this using an RNN layer. I've tried changing the activation functions, the loss function and the optimisers, but nothing seems to be working. I'm not sure if I'm missing something trivial or not  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2022-01-09. Score: 1
  
  The model seems to train just fine (when measured by the MSE loss), accuracy metric is only relevant when the prediction is a true / false type.
  
  Arguably the network's structure isn't ideal for this problem, but that is beside the point.
  
  > **Comments:**
  > **username_0**: isn't there still accuracy for the error? from the real result  
  > **username_0**: it doens't work. I tested with `print([(x, y[0]) for x,y in zip( y_val, model.predict(x_val))])` after 200 epochs and the results seem random, compared to the `y_val`  
  > **username_2**: After 100 epochs my code says `((model.predict(x_val) - y_val)**2).mean()` is 0.063620539. And the scatter plot looks good as well, correlation coefficient is 0.99984668648.  
  > **username_0**: `[(1.249716031816869, 0.32068107), (1.1568286658676914, 0.31521273), (1.3370053550792722, 0.33378834), (1.1397021505376013, 0.23554398), (1.1691912669776516, 0.30106655), (1.0633291121420687, 0.28948098), (0.849716930324254, 0.17947169), (1.012984152099238, 0.2649205), (1.018326969664438, 0.24658701)]` look, there's no correlation. The MSE isn't relative to anything so is effectively meaningless  
  > **username_0**: https://i.imgur.com/YJthW6Y.png  
  > **username_0**: https://i.imgur.com/oqU11l8.png  
  
  ---
  
  