Machine learning for predictive analytics: define the target, beat a baseline, test fairly
Learn predictive analytics through a clear target, prediction-time inputs, a baseline and held-out evaluation. Work through a forecast example and common errors.
Machine learning for predictive analytics uses observed examples to estimate an outcome that is unknown at prediction time. It can predict a number, such as processing duration, or a category, such as whether a request will need review. The essential steps are defining the target, using available inputs, comparing a baseline and evaluating on examples kept out of fitting.
This guide works through an invented daily-demand example. It focuses on constructing a trustworthy prediction experiment. For the decision and operational consequences that follow a prediction, read machine learning for business analytics.
Define a target that has a deadline
Suppose you predict tomorrow's total notebook demand at 6 p.m. today. One row represents one prediction date. The target is the following day's demand. Inputs might include earlier demand and calendar facts already known by 6 p.m.
| Candidate input | Available at prediction time? | Use in this experiment |
|---|---|---|
| Today's demand recorded by 6 p.m. | Yes, if that is genuinely the complete intended input | Document the collection cutoff |
| Tomorrow's day of week | Yes | A possible calendar feature |
| A promotion scheduled before the cutoff | Yes | A possible planned-event feature |
| Tomorrow's final sales total | No | Exclude it |
| A later revision to today's records | Not as originally observed | Use a historical snapshot or explain the limitation |
A dataset assembled today may contain fields that did not exist at the historical prediction time. Preserving snapshots or reconstructing availability is part of the experiment, not an administrative detail.
Calculate a baseline before fitting a model
In this teaching example, we keep three later days for evaluation. The baseline repeats the previous day's demand. A candidate model produces separate predictions after being fitted on earlier data; the numbers here are stipulated so you can calculate the evaluation without code.
| Held-out day | Actual demand | Baseline prediction | Candidate prediction |
|---|---|---|---|
| Day A | 20 | 18 | 21 |
| Day B | 30 | 20 | 27 |
| Day C | 25 | 30 | 24 |
The baseline's absolute errors are 2, 10 and 5, so MAE is 17 / 3 = 5.67 units. The candidate's errors are 1, 3 and 1, so MAE is 5 / 3 = 1.67 units. On these three invented cases, the candidate has lower average absolute error.
That is the full extent of the result. Three stipulated predictions do not establish stable improvement, explain how a model was fitted or show performance in other periods. A real report must include those details. Keep a record of the data window, features, training procedure and model-selection decisions so the result can be reproduced.
Try it yourself: change the candidate's Day B prediction from 27 to 40. Its new absolute errors are 1, 10 and 1, giving MAE 4.00. It still beats this baseline on the three-row average, while badly overpredicting on one day. Describe what an average alone hides.
Split the data to match the prediction
For tomorrow-facing predictions, train on earlier data and evaluate on later data. If you evaluate at several historical cutoffs, each cutoff needs its own training-only transformations. Keep a final period apart while choosing features and settings.
A gap between training and validation may be needed when target windows overlap or outcomes arrive late. For irregular timestamps, define calendar boundaries explicitly rather than assuming equally spaced rows. The right design depends on the horizon and data availability.
For a different application, such as predictions for entirely new shops, you may also need to hold out whole shops. Explain whether you are testing new dates, new entities or both. A random row split is not a substitute for making that choice.
Read data leakage in machine learning before building a feature table. A target shifted in the wrong direction can make future information look like an ordinary column.
Choose a metric that matches the output
| Output | Useful starting measure | What else to inspect |
|---|---|---|
| Numerical demand | MAE in demand units | Large misses, seasonality and subsets |
| Urgent / not urgent label | Precision and recall at a chosen threshold | Review volume and missed urgent cases |
| Estimated probability | A probability-scoring measure and calibration checks | Behavior at decision thresholds |
There is no single metric that makes every prediction useful. MAE gives a readable scale for this example, but it weights each unit of error the same way. The business analytics example shows how shortage and surplus consequences can differ.
A point prediction also does not describe its own uncertainty. If a user needs an interval, define its intended interpretation and evaluate coverage and width on appropriate held-out data. Do not convert a mean error into a guaranteed range.
Common questions
Is predictive analytics always machine learning?
No. It can use statistical methods and simple forecasting rules as well. A last-value baseline is already a prediction method. Compare approaches on the same task before deciding whether a learned model adds enough value.
Can prediction show what caused an outcome?
A predictive association is not, by itself, a causal result. A model may use signals correlated with demand without showing that changing those signals would change demand. The correlation and causation lesson explains the distinction.
What should I build as a first coding project?
Begin with the linear regression example to practise training, prediction and a baseline on known data. Then build a date-aware feature table and evaluate on later dates. The pandas projects cover joins and missing dates you will need to handle.
Learn the skills behind a prediction report
SchoolWhool's Data Tools course develops the table, array and estimator workflow. The Statistics course covers the reasoning needed to interpret variation and evidence. Follow the Machine Learning syllabus for models, checking current lesson availability.
If you are starting from zero, use machine learning for beginners to connect those tracks in order. A free account adds quizzes and saved progress. Pro adds practice for every lesson, projects, certificates and weekly live sessions with Gaurav.
References
See the official TimeSeriesSplit documentation for an expanding-window split on ordered, equally spaced observations, and the mean_absolute_error API for the metric used in the worked table. The numerical examples are original.