Artificial Intelligence (AI) October 18, 2026 0

Time Series Forecasting With AI: Sales, Demand and Weather

By Admin 5 min read

Many business questions are about the future: How many units will we sell next month? How much electricity will the grid need tomorrow? Will it rain this week? These are time series forecasting problems, where data points are ordered in time and the goal is to predict future values. Good forecasting combines basic statistics with machine learning and a lot of common sense.

What is a time series?

A time series is a sequence of observations recorded at regular intervals: daily sales, hourly temperature, weekly website visits. Unlike ordinary tabular data, the order matters, and nearby points are usually related.

Components of a time series

  1. Trend: a long-term increase or decrease.
  2. Seasonality: repeating patterns at fixed periods, such as weekly shopping cycles, yearly festival peaks (Dashain and Tihar for Nepali retailers) or monsoon effects.
  3. Cycles: longer, irregular fluctuations linked to the economy.
  4. Noise (residual): random variation.
  5. Events and shocks: promotions, holidays, strikes, pandemics and other special days that break normal patterns.

Plotting your data is the first step. Look for these components and for unusual values.

Start with baselines

Always begin with simple forecasts. If a complicated model cannot beat them, it is not worth using.

  • Naive: tomorrow equals today.
  • Seasonal naive: next Monday equals last Monday.
  • Moving average: the average of the last k periods.

Classic statistical models

  • Exponential smoothing (ETS, Holt-Winters): weighted averages that handle trend and seasonality. Fast and strong for many business series.
  • ARIMA and SARIMA: model the relationship between a value and its past values and errors, with differencing to remove trends and seasonal terms.
  • Prophet-style additive models: decompose into trend, seasonality and holiday effects, friendly for business users.

Machine-learning approaches

Turn forecasting into a supervised problem by creating features from the past.

  • Lag features: value 1, 7, 14, 28 days ago
  • Rolling statistics: mean and standard deviation over a window
  • Calendar features: day of week, month, holiday flags, festival indicators
  • External variables: price, promotions, weather, ad spend

Then use models like gradient boosting (LightGBM, XGBoost) or random forests. For many related series (thousands of products), a single global model with product identifiers often does well.

Deep learning and foundation models

Neural networks such as LSTMs, temporal convolution networks and transformer-based models can capture complex patterns, especially with lots of data. Recently, pretrained time-series foundation models have appeared that can forecast new series with little or no training. They are promising but should always be compared against simple baselines on your own data.

A worked example in Python

This example creates weekly sales with trend and seasonality, then compares a seasonal naive baseline with Holt-Winters exponential smoothing:

import numpy as np
import pandas as pd
from statsmodels.tsa.holtwinters import ExponentialSmoothing

rng = np.random.default_rng(0)
weeks = pd.date_range("2022-01-02", periods=156, freq="W")
trend = np.linspace(100, 160, 156)
season = 20 * np.sin(2 * np.pi * np.arange(156) / 52)
sales = pd.Series(trend + season + rng.normal(0, 6, 156), index=weeks)

train, test = sales[:-12], sales[-12:]            # hold out the last 12 weeks

seasonal_naive = sales.shift(52)[-12:]            # same week last year

model = ExponentialSmoothing(train, trend="add", seasonal="add", seasonal_periods=52).fit()
forecast = model.forecast(12)

def mae(a, f):
    return float(np.mean(np.abs(a.values - f.values)))

print("Seasonal naive MAE:", round(mae(test, seasonal_naive), 2))
print("Holt-Winters MAE:  ", round(mae(test, forecast), 2))

The numbers depend on the random data, but the workflow is what matters: hold out the most recent period, compare to a baseline, measure error.

Validate the right way

  • Never shuffle time series data when splitting. Train on the past, test on the future.
  • Use time-series cross-validation (rolling origin): train on a window, forecast the next period, move the window forward and repeat. Scikit-learn's TimeSeriesSplit helps.
  • Evaluate across multiple periods, including special seasons.
  • Beware of leakage: do not use information that would not be available at forecast time, such as next week's promotion results.

Choosing error metrics

  • MAE: average absolute error, easy to interpret in original units.
  • RMSE: penalises big misses.
  • MAPE / sMAPE: percentage errors, but unstable when values are near zero.
  • MASE: error scaled against a naive forecast, useful for comparing series.
  • Pinball loss / coverage for prediction intervals.

Choose metrics aligned with business costs. Running out of stock may cost more than overstocking, so you might prefer a forecast that errs on the high side for critical items.

Forecast intervals, not just points

A single number hides uncertainty. Provide ranges, such as "between 900 and 1,150 units with 80 percent probability". Planners can then set safety stock according to risk tolerance.

Special situations

  • New products with no history: use similar products, category averages and expert input.
  • Intermittent demand (many zeros): specialised methods like Croston's work better.
  • Changing patterns after shocks: consider excluding or flagging abnormal periods.
  • Hierarchies: forecasts for products, categories and regions should add up consistently.
  • Weather forecasting: modern systems use physics-based simulation plus machine learning, a different league from simple statistical models. For your own business, use professional weather forecasts as input features rather than building your own.

Making forecasts useful

  1. Understand the decision: ordering, staffing, budgeting.
  2. Combine the model with expert knowledge about upcoming events.
  3. Update forecasts regularly and track accuracy.
  4. Monitor for drift and rebuild when performance drops.
  5. Explain assumptions in simple terms.

Frequently Asked Questions

How much history do I need?

At least two full seasonal cycles for reliable seasonality estimates. More helps, but older data may be less relevant.

Is deep learning better than classic methods?

Not automatically. On a single short series, simple methods are often hard to beat. Deep models shine with many related series and rich data.

Can AI predict the stock market?

Markets are noisy and adaptive. Claims of reliable prediction should be treated with great caution.

What if my data has missing dates?

Fill gaps using appropriate methods or treat them as missing values, after checking why they occurred.

Conclusion

Forecasting starts with understanding trend and seasonality, beating simple baselines, validating on future periods and communicating uncertainty. Choose methods that fit your data volume and decisions rather than the latest fashion.