LSTM Model for Product Demand Prediction: Data Preparation, Training, and Analysis

Predict a company's product demands based on their historical data

Posted by Dirouz on August 7, 2024

Predicting Product Demand with LSTM: A Step-by-Step Approach Using Historical Data

The objective here is to train a LSTM model to predict a company's product demands based on their historical data.

As per usual we need to gather the proper data to train our model with which in this case we wrote a CSV generator function including 4 columns; one for date and the rest for costumer demands related to 3 products.

Now for our main script we load the data generated in the previous step then make it into a sequence for our LSTM model input. We build the LSTM model afterward and pass 'relu' as activation function.

Then we move forward to training the model with the sequence created in step 2 store its predictions and at last we visualize the data with date-demand plots.

We can also change the model's activation function back to its default value which is 'tanh' and compare the results. as you can see in the figure-4 (product1(tanh)) the hit points are a bit wider compared to 'relu' and we might get more accurate results in different cases for example if the data appears in wider ranges.

... ... ...

Conclusion

This project demonstrates how an LSTM model can effectively predict product demand using historical data. By sequencing data and experimenting with activation functions, we achieved accurate forecasts, especially with tanh for broader demand variations. This approach enables more data-driven inventory management and can be further refined for improved accuracy.