Skip to main content

Why does my LSTM model predict wrong values although the loss is decreasing?

I am trying to build a machine learning model which predicts a single number from a series of numbers. I am using an LSTM model with Tensorflow.

You can imagine my dataset to look something like this:

Index x data y data
0 np.array(shape (10000,1) ) numpy.float32
1 np.array(shape (10000,1) ) numpy.float32
2 np.array(shape (10000,1) ) numpy.float32
... ... ...
56 np.array(shape (10000,1) ) numpy.float32

Easily said I just want my model to predict a number (y data) from a sequence of numbers (x data).

For example like this:

  • array([3.59280851, 3.60459062, 3.60459062, ...]) => 2.8989773
  • array([3.54752101, 3.56740332, 3.56740332, ...]) => 3.0893357
  • ...

x and y data

From my x data I created a numpy array x_train which I want to use to train the network. Because I am using an LSTM network, x_train should be of shape (samples, time_steps, features). I reshaped my x_train array to be shaped like this: (57, 10000, 1), because I have 57 samples, which each are of length 10000 and contain a single number.

The y data was created similarly and is of shape (57,1) because, once again, I have 57 samples which each contain a single number as the desired y output.

Current model attempt

My model summary looks like this: current model

The model was compiled with model.compile(loss="mse", optimizer="adam") so my loss function is simply the mean squared error and as an optimizer I'm using Adam.

Current results

Training of the model works fine and I can see that the loss and validation loss decreases after some epochs. The actual problem occurs when I want to predict some data y_verify from some data x_verify. I do this after the training is finished to determine how well the model is trained. In the following example I simply used the data I used for training to determine how well the model is trained (I know about overfitting and that verifying with the training set is not the right way of doing it, but that is not the problem I want to demonstrate right not).

In the following graph you can see the y data I provided to the model in blue. The orange line is the result of calling model.predict(x_verify) where x_verify is of the same shape as x_train.

current results

I also calculated the mean absolute percentage error (MAPE) of my prediction and the actual data and it came out to be around 4% which is not bad, because I only trained for 40 epochs. But this result still is not helpful at all because as you can see in the graph above the curves do not match at all.

Question:

What is going on here?

Am I using an incorrect loss function?

Why does it seem like the model tries to predict a single value for all samples rather than predicting a different value for all samples like it's supposed to be?

Ideally the prediction should be the y data which I provided so the curves should look the same (more or less).

Do you have any ideas?

Thanks! :)



source https://stackoverflow.com/questions/73457069/why-does-my-lstm-model-predict-wrong-values-although-the-loss-is-decreasing

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data