We built a small lab model to test how an LSTM can forecast monthly revenue.
This is not a production model.
It is a learning model.
The goal was simple.
Can we take monthly revenue history, train a neural network, and generate a short-term forecast for the next quarter?
What We Built
We built a Python model using PyTorch.
The model uses an LSTM network to forecast revenue.
The input is 12 months of revenue history.
The output is the next 3 months of revenue.
So the model is asking a simple planning question:
Based on the last 12 months, what could the next 3 months look like?
This is similar to how FP&A teams often think about rolling forecasts.
Look at recent history.
Check the trend.
Check seasonality.
Then estimate the next quarter.
The Data
For this lab, we generated sample revenue data.
The data includes:
- Monthly dates
- Revenue values
- Growth trend
- Seasonality
- Random noise
The sample data starts in January 2016 and creates 96 months of revenue.
This gives the model enough data to train and test.
We used generated data because this lab is focused on the model pattern, not on a client dataset.
Why We Scaled the Data
Before training, we scaled the revenue values using MinMaxScaler.
This converted the revenue values into a smaller range.
Neural networks usually train better when the input values are scaled.
After the model made predictions, we converted the forecast back to actual revenue dollars.
That step matters.
The model trains on scaled values, but FP&A users need to see revenue in dollars.
How the Training Windows Work
We used a 12-month lookback window.
That means each training example contains 12 months of revenue history.
The target is the next 3 months.
Example:
- Input: Jan 2020 to Dec 2020
- Target: Jan 2021 to Mar 2021
Then the window moves forward by one month.
This creates many training samples from one revenue series.
That is the main idea behind time series windowing.
The Model
The model uses two LSTM layers.
The first LSTM layer has 128 hidden units.
The second LSTM layer has 64 hidden units.
We also added dropout after each LSTM layer.
Dropout helps reduce overfitting during training.
The final layer outputs 3 values.
Those 3 values represent the next 3 forecast months.
Training the Model
We trained the model for 80 epochs.
The loss function was Mean Squared Error.
The optimizer was Adam.
We also used a learning rate scheduler.
If validation loss stopped improving, the learning rate was reduced.
We saved the best model based on validation loss.
That way, we did not just use the final epoch.
We used the model version that performed best on the validation data.
How We Evaluated It
After training, we compared forecast values against actual values from the test data.
We calculated:
- MAE
- RMSE
- MAPE
- R²
These metrics help us understand how close the model was to the actual revenue values.
For this first lab, we focused on the first forecast month, also called M+1.
That keeps the evaluation simple.
What the Chart Shows
The chart compares:
- Actual revenue
- Forecasted revenue for M+1
This is useful because it shows whether the model is following the shape of the revenue pattern.
A metric can tell us error.
A chart helps us see the pattern.
For planning work, both are useful.
Next Quarter Forecast
After evaluation, we used the last 12 months of revenue history to predict the next 3 months.
The model produced:
- Month 1 forecast
- Month 2 forecast
- Month 3 forecast
- Quarter total
This is the part that connects the lab back to EPM.
A planning model usually needs a forecast period.
In this case, the model produced a next-quarter revenue forecast.
What We Learned
This lab shows that a simple LSTM model can be used to forecast monthly revenue.
It also shows the basic workflow:
- Create or load time series data
- Scale the data
- Create lookback windows
- Train the model
- Evaluate the output
- Generate a future forecast
This is not enough for production.
A real EPM use case would need better source data, validation, model monitoring, business review, and controls around how forecast values are used.
But as a lab, this is a useful starting point.
It gives us a working pattern for testing AI and ML forecasting ideas in an EPM context.
Final Thought
The most useful part of this lab is not the LSTM itself.
The useful part is the process.
We took a planning question, built a small model, tested the output, and reviewed the result.
That is how AI and ML work should start in EPM.
Small lab.
Clear input.
Clear output.
Review the result before trusting it.
Link- https://colab.research.google.com/drive/1swVX7nwLcVLpPcKp-xBNLcD98R2VZYN1