Calculadora COMEX Perú

Home / Digital business and AI / Module 5

5.3 Predictive analytics with AI

Predictive analytics uses your past data to estimate what is likely to happen: how much you will sell, which customers will leave, how much to buy. You will see how to start simple, measure the error and decide with a range.

Module 5: Scale up and go international · Reviewed on 12/10/2026 · Español

Goal: Tell apart the four types of analytics, calculate a forecast with a moving average and its error in a backtest, and decide how many units to order with a range.

Predictive analytics uses past data to estimate what is likely to happen. It does not guess: it finds patterns, such as monthly purchases or repurchase habits, and projects them forward. It is one step on a ladder. Descriptive analytics tells you what happened, diagnostic analytics explains why, predictive analytics estimates what will happen and prescriptive analytics suggests what to do. A small business gains a lot from the first two before jumping to the third.

In a digital business it helps with four decisions. Demand: how many units to buy before a campaign. Repurchase: which customers are about to stop buying and deserve a message. Customer value: how much a customer is expected to spend over time, to decide how much to pay to acquire them. Advertising and prices: which products or audiences perform best. Pick a decision you make by eye today and that costs money when it goes wrong, such as overbuying or running out of stock.

AI helps in two ways. Machine learning models learn from your data and already come built into many store and advertising platforms. General-purpose AI assistants can read a table, calculate a forecast and explain the method. With either one, start simple: a moving average (the average of the last few months) with a seasonal adjustment is often enough. A complex model with little data looks precise and fails. Ask the assistant to show the formula and check the math yourself.

Data rules. You need at least 12 months of sales by product and by month; with 24 you can see the seasons better, such as Mother's Day or Christmas. Remove duplicates and flag months with promotions or with no stock, because sales lost to stockouts do not show up in your figures. Before using a forecast, run a backtest: predict months that already happened, without looking at them, and compare with the actual figures. The mean absolute percentage error (MAPE) is the average of how far off you were each month, as a percentage.

A forecast is a range, not an exact figure, and it breaks when something changes suddenly. Decide with the range, leave a safety margin and review it every month. If you use customer data, do so with their consent and following the rules of Law No. 29733, the Personal Data Protection Law. Also take care with cases where the model decides about a person, such as whether to grant a loan: Peru's AI regulation calls for more transparency and human review. Large-scale demand planning is covered in the area on Supply Chain, Technology and AI (scm).

Key ideas

Type of analyticsQuestion it answersExample in your store
DescriptiveWhat happened?In October you sold 170 units
DiagnosticWhy did it happen?Sales rose because of an email campaign
PredictiveWhat is likely to happen?November will be around 196 units
PrescriptiveWhat should I do?Order 174 units from the supplier

Worked example

Café Altura forecasts November and calculates its order
  1. Café Altura (a fictitious company from Arequipa) sells 250 g bags of coffee through its online store. Its recent sales, in units, are: May 190 (with the Mother's Day campaign), June 150, July 160, August 155, September 165 and October 170. With October closed, the supplier delivers in 5 days and the company must decide how much to order for November.
  2. Base forecast with a 3-month moving average (August to October): (155 + 165 + 170) ÷ 3 = 490 ÷ 3 = 163.3 units.
  3. Backtest with three past months. October: (160 + 155 + 165) ÷ 3 = 160 versus 170 actual, error 10 ÷ 170 = 5.9%. September: (150 + 160 + 155) ÷ 3 = 155 versus 165, error 10 ÷ 165 = 6.1%. August: (190 + 150 + 160) ÷ 3 = 166.7 versus 155, error 11.7 ÷ 155 = 7.5%. MAPE = (5.9 + 6.1 + 7.5) ÷ 3 = 6.5%.
  4. Seasonal adjustment. Last year it sold 130, 135 and 140 units from August to October (average 135) and 162 in November. November factor = 162 ÷ 135 = 1.20. Forecast = 163.3 × 1.20 = 196 units. The factor comes from a single year, so it is an estimate.
  5. Range with the mean error: 196 × 6.5% = 12.7. The forecast goes from 196 − 12.7 = 183 to 196 + 12.7 = 209 units.
  6. Order decision. At the start of November it has 35 units in stock. To cover the high end it orders 209 − 35 = 174 units. If actual demand is 196, it has 209 − 196 = 13 units left over, about 2 days of sales (196 ÷ 30 = 6.5 per day).
  7. Check with AI. It sends an assistant only the table of monthly totals, with no customer data, and asks for the method and the result. It compares this with its own math; if the difference exceeds 2 units, it looks for the reason. In December it records November's actual sales to update the error.

Result: The November forecast is 196 units, with a range of 183 to 209 based on a mean error of 6.5%. To cover the high end with 35 units in stock, Café Altura orders 174 and accepts a possible surplus of 13 units.

Real cases

Peru regulates artificial intelligence by risk level

09/09/2025

On 09/09/2025, Supreme Decree No. 115-2025-PCM was published in El Peruano. It sets the regulations for Law No. 31814 on the use of artificial intelligence. It distinguishes prohibited, high-risk and acceptable-risk uses. Among the high-risk uses it cites systems that determine credit assessment (except fraud detection) and those used to hire or dismiss workers. For them it calls for transparency and human oversight, and it sets adaptation periods of one to four years depending on sector and size.

Use predictions for stock and campaigns, but if a model decides about a person, such as a loan or a job, check whether it is high risk and keep an explanation and human review.

Source: Congreso de la República – Decreto Supremo N.° 115-2025-PCM, Reglamento de la Ley N.° 31814

Amazon and the limits of forecasting a sudden change

2022

In its letter to shareholders on fiscal year 2021, Amazon acknowledges that it did not know what to expect in 2021 and that pandemic growth amounted to what it had forecast for three years, happening in about 15 months. To meet that demand it had to double its fulfillment network in 24 months. It also expected the impact of COVID-19 to ease by the end of 2021, but then came the Omicron variant and, later, rising costs from the war in Ukraine. Not even a company with enormous volumes of data anticipated the change.

Treat the forecast as a range, review it every month and keep flexible capacity, for example orders in batches or a logistics operator that can absorb peaks.

Source: Amazon – 2021 Letter to Shareholders

Common mistakes

Practise with the calculators, the COMEX Simulator and the review questions on the main page.

Open this topic in the calculator →
← Previous topic: Multichannel and omnichannelNext topic: Project: your digital business at scale →