How to Forecast Sales With Machine Learning
What Data You Need
The core of a sales forecast is historical revenue data broken into regular time periods (daily, weekly, or monthly). Each row represents one time period, and the target column is the revenue amount. The more time periods you have, the better the model can learn patterns, especially seasonal ones.
Beyond raw revenue, include features that influence sales:
- Time features: Month, day of week, week of year, quarter, is_holiday flag
- Marketing: Ad spend, email campaigns sent, SMS broadcasts sent, active promotions
- Customer metrics: New customers acquired that period, active customer count, average order value
- Product data: Number of products listed, new product launches, out-of-stock items
- External factors: Competitor activity, industry events, weather (for retail), economic indicators
- Lag features: Last month's revenue, revenue 12 months ago (same month last year), rolling 3-month average
For monthly forecasting, aim for at least 24 months of history to capture annual seasonality. For daily forecasting, at least 6-12 months. See How Much Data Do You Need for more guidance.
Building the Forecast Model
Export revenue by time period along with the features above. Each row is one time period (one month, one week, or one day). Create time-based features from your dates: month number, day of week, quarter, and any lag features. See How to Prepare Your Data.
Upload the CSV to the Data Aggregator app. Set the revenue column as your target. Select all other columns as input features. The platform will handle the training process from here.
For sales forecasting, gradient boosting regression typically performs best because it captures non-linear relationships and interactions between features. It handles the complex interplay of seasonality, marketing effects, and customer behavior better than linear models.
Check the model's error metrics after training. For revenue forecasting, look at mean absolute error (how many dollars the predictions are off on average) and mean absolute percentage error (what percentage the predictions are off). A model that predicts monthly revenue within 10-15% is quite useful for planning. See How to Test Model Accuracy.
Create rows for future time periods with your planned or expected feature values (planned marketing spend, expected customer count, known events). Send these through the model to get revenue predictions. Predictions cost zero credits, so you can run multiple scenarios quickly.
Scenario Planning
The zero prediction cost enables powerful scenario planning. Create multiple versions of future data with different assumptions and compare the forecasts:
- Baseline scenario: Current marketing spend and customer growth trends continue
- Growth scenario: Double the marketing budget, add a new product line
- Conservative scenario: Cut marketing by 30%, no new products
- Seasonal adjustment: What if this holiday season is 20% stronger than last year
Each scenario takes seconds to score, giving you a range of possible outcomes to plan around instead of a single number.
Improving Forecast Accuracy
Add More Relevant Features
The biggest accuracy gains come from adding features that genuinely influence sales. If email campaigns drive purchases, include email volume and open rates. If weather affects foot traffic, include temperature data. Every relevant signal you add helps the model make better predictions.
Use Lag Features
Lag features (last month's revenue, same month last year, rolling averages) are often the single most predictive input for time series forecasting. They capture momentum and seasonality directly. Always include at least "revenue last period" and "revenue same period last year" as features.
Retrain Periodically
Markets change, businesses evolve, and customer behavior shifts. Retrain your forecast model quarterly to incorporate the most recent data. A model that includes the last quarter's actuals will make better predictions for the next quarter. See How to Retrain Models With New Data.
Build a sales forecast model on your own revenue data. Get data-driven predictions for better business planning.
Get Started Free