A sales forecast can look convincing on a chart and still be difficult to use.

The model might produce numbers for the next six months, but a business also needs to know how those numbers were produced, how uncertain they are and whether the evaluation reflects the way the forecast will actually be used.

In a retail forecasting project, I worked through monthly sales aggregation, time-based features and a comparison between Linear Regression and Random Forest. Here’s how I approach the process, and the checks I’d make before relying on the result.

Start with the question

Before choosing a model, be clear about what you’re forecasting. Is it total sales for the business, sales for each product, or sales by store and month? The answer determines how the data should be grouped.

It’s also useful to ask how far ahead the forecast needs to go. Predicting next month’s sales is a different task from forecasting six months ahead. As the forecast horizon grows, uncertainty usually becomes more important to communicate.

Prepare the time series

Sales data often starts at the transaction level. For a monthly forecast, the first step is to aggregate it by month.

import pandas as pd sales = pd.read_csv("retail_sales.csv") sales["date"] = pd.to_datetime(sales["date"]) monthly_sales = ( sales.set_index("date")["sales"] .resample("MS") .sum() .rename("sales") .reset_index() ) monthly_sales = monthly_sales.sort_values("date") 

This assumes the file has columns called date and sales. Use the actual column names in your dataset. Also check for missing months, duplicate records and unusual values before fitting a model. A zero-sales month might be real, or it might mean the data was missing.

Create features using only past information

Calendar features such as month number can help a model learn seasonal patterns. Lag features can capture recent sales history, but they must be created carefully: a forecast for a given month can only use values that would have been available at the time.

monthly_sales["month"] = monthly_sales["date"].dt.month monthly_sales["year"] = monthly_sales["date"].dt.year monthly_sales["lag_1"] = monthly_sales["sales"].shift(1) monthly_sales["lag_12"] = monthly_sales["sales"].shift(12) model_data = monthly_sales.dropna().copy() 

Here, lag_1 is the previous month’s sales, and lag_12 is sales from the same month a year earlier. Those features can be helpful when the data has enough history, but they are not automatically useful for every dataset.

Respect the order of time

A random train-test split can mix future observations into the training set. For forecasting, that can give an overly optimistic evaluation.

A simple approach is to train on earlier months and test on the most recent months:

split_index = int(len(model_data) * 0.8) train = model_data.iloc[:split_index] test = model_data.iloc[split_index:] features = ["month", "year", "lag_1", "lag_12"] X_train = train[features] y_train = train["sales"] X_test = test[features] y_test = test["sales"] 

For a more thorough evaluation, use rolling time-based validation. Train on an initial period, test on the next period, then move the cutoff forward and repeat. That helps show whether the model performs consistently across different periods.

Compare models against a simple baseline

Linear Regression can provide an understandable starting point. A Random Forest can capture nonlinear patterns, but it may not extrapolate trends well beyond the values it has seen.

from sklearn.ensemble import RandomForestRegressor from sklearn.linear_model import LinearRegression linear_model = LinearRegression() forest_model = RandomForestRegressor( n_estimators=200, random_state=42, ) linear_model.fit(X_train, y_train) forest_model.fit(X_train, y_train) linear_forecast = linear_model.predict(X_test) forest_forecast = forest_model.predict(X_test) 

It’s also worth comparing both against a simple baseline, such as predicting that next month will be the same as the previous month. A more complex model should earn its place by doing better on data it did not train on.

Evaluate errors in context

No single metric tells the whole story. Mean absolute error is easy to interpret in the same units as sales. Root mean squared error gives more weight to large errors. Percentage-based metrics can be difficult to interpret when actual sales are zero or close to zero.

from sklearn.metrics import mean_absolute_error, mean_squared_error import numpy as np mae = mean_absolute_error(y_test, forest_forecast) rmse = np.sqrt(mean_squared_error(y_test, forest_forecast)) print(f"MAE: {mae:.2f}") print(f"RMSE: {rmse:.2f}") 

A metric should be considered alongside a plot of actual and predicted values. That makes it easier to notice whether the model consistently misses peaks, lags behind a trend or performs poorly during particular periods.

Treat the forecast as an estimate

A forecast is not a promise about what will happen. Promotions, stock availability, price changes and unexpected events can all affect sales, and a model may not know about them.

When sharing a forecast, explain the period it covers, the data used, the evaluation method and any important limitations. If possible, show a range or scenario alongside the central estimate rather than presenting one line as certainty.

A useful sales forecast is not just the model with the best score. It is a forecast built with the right time boundaries, compared against a simple baseline and explained in a way that helps people make decisions.