Module 5 — When is a prediction good?
Lesson 12 of 14
Spatial prediction
5.12 Spatial Prediction
Suppose an AI system predicts:
Electricity demand tomorrow at 18:00 will be 40 GW.
Useful.
But where?
Perhaps one part of the country has abundant generation while another is approaching the physical limits of its electricity network.
Perhaps total demand is exactly as predicted, while demand in one neighbourhood is dramatically higher than expected.
At the national level, the forecast might look excellent.
At the local level, it might completely miss the problem that actually matters.
This introduces another fundamental dimension of prediction:
space.
Just as events happen at particular times, they also happen in particular places.
And when we aggregate across space, we can destroy information that may be essential for making good decisions.
Everything happens somewhere
Consider some things we might want to predict:
- electricity demand,
- rainfall,
- traffic congestion,
- air pollution,
- house prices,
- disease outbreaks,
- crop yields,
- flooding,
- crime,
- broadband demand,
- hospital admissions,
- renewable generation.
None of these occurs uniformly across the world.
They have a location.
We might represent an observation as:
[ y(s,t) ]
where:
- (s) represents space,
- (t) represents time.
Instead of predicting only:
[ \hat{y}_{t+h} ]
we might want to predict:
[ \hat{y}(s,t+h) ]
Now we are asking:
What will happen, when will it happen, and where will it happen?
Location can be a feature
Suppose we want to predict house prices.
A house has characteristics such as:
- number of bedrooms,
- floor area,
- age,
- condition,
- energy efficiency.
But location may be enormously important.
Two physically identical houses can have radically different prices because they are located in different places.
We might therefore construct a model such as:
[ \hat{P}
f( \text{size}, \text{bedrooms}, \text{age}, \text{location}, \ldots ) ]
Location might be represented by:
- latitude and longitude,
- postcode,
- neighbourhood,
- administrative region,
- distance from a city centre,
- distance from transport,
- local environmental characteristics.
The question is not merely:
What is this object like?
but also:
Where is it?
Nearby things are often related
Spatial data frequently exhibits spatial dependence.
Temperatures at neighbouring locations are often similar.
House prices in neighbouring streets may be related.
Air pollution measured at one sensor may resemble pollution at nearby sensors.
Electricity demand in neighbouring areas may respond to the same weather.
This gives us a useful intuition:
Things that are close together in space are often more related than things that are far apart.
Not always.
But often enough that location can contain important predictive information.
Distance matters
Suppose we observe temperatures at three weather stations.
Station A is:
[ 1\text{ km} ]
from a location where we want to estimate temperature.
Station B is:
[ 10\text{ km} ]
away.
Station C is:
[ 500\text{ km} ]
away.
All else being equal, Station A may tell us more about local conditions than Station C.
We might therefore imagine predictions depending on distance:
[ w_{ij}=f(d_{ij}) ]
where:
- (d_{ij}) is the distance between locations (i) and (j),
- (w_{ij}) represents how strongly information from one location influences another.
Often:
[ d_{ij}\uparrow \quad\Rightarrow\quad w_{ij}\downarrow ]
Information becomes less relevant as distance increases.
But physical distance is not always the right notion of distance.
Not all neighbours are geographical neighbours
Consider an electricity network.
Two houses may be physically close together but connected to different parts of the network.
Another pair may be further apart geographically but connected through the same electrical infrastructure.
For electricity, the relevant relationship may therefore be:
[ \text{network topology} ]
rather than simply:
[ \text{geographical distance} ]
The same principle appears elsewhere.
For transport, two places connected by a fast railway may effectively be "closer" than their physical distance suggests.
For social networks, relationships are defined by connections between people.
For the internet, topology depends on network infrastructure.
For supply chains, locations are connected through flows of materials and goods.
So spatial prediction sometimes requires us to ask:
What does "nearby" actually mean for this system?
Spatial aggregation
Suppose four regions have electricity demand:
| Region | Demand |
|---|---|
| A | 5 GW |
| B | 5 GW |
| C | 5 GW |
| D | 25 GW |
Total demand is:
[ 40\text{ GW} ]
A national forecast of:
[ 40\text{ GW} ]
would be perfect.
But imagine the forecast expected:
| Region | Forecast |
|---|---|
| A | 10 GW |
| B | 10 GW |
| C | 10 GW |
| D | 10 GW |
The national total is still:
[ 40\text{ GW} ]
So at the national level:
[ \text{forecast error}=0 ]
Yet every regional forecast is badly wrong.
This demonstrates something extremely important:
Errors can cancel when data is aggregated.
A model can therefore appear accurate at a large spatial scale while being poor at the locations where decisions actually need to be made.
Aggregation destroys information
Suppose electricity demand across ten neighbourhoods is represented by:
[ D_1,D_2,\ldots,D_{10} ]
If we aggregate them:
[ D_{\text{total}}
\sum_{i=1}^{10}D_i ]
we retain the total demand.
But we lose information about its distribution.
Many completely different spatial states can produce exactly the same total.
For example:
[ 10+10+10+10=40 ]
and:
[ 2+3+5+30=40 ]
have the same aggregate value.
But if each region has a maximum infrastructure capacity of:
[ 15 ]
the second situation contains a serious local problem that the aggregate number completely hides.
This is why spatial resolution matters.
The right spatial scale depends on the decision
Imagine predicting rainfall.
For deciding whether to take an umbrella on a walk, a city-level forecast might be useful.
For managing a national water system, regional forecasts may be sufficient.
For predicting flash flooding, we may need much more local information.
The same is true of electricity.
A national demand forecast might help with:
- national generation planning,
- fuel requirements,
- broad system adequacy.
But it may tell us very little about:
- a constrained transmission line,
- a distribution transformer,
- a local battery,
- an EV charging cluster,
- a neighbourhood with large numbers of heat pumps.
There is therefore no universally correct spatial resolution.
The appropriate resolution depends on:
[ \text{prediction} \rightarrow \text{decision} \rightarrow \text{physical system} ]
The modifiable areal unit problem
Spatial analysis contains a particularly interesting problem known as the modifiable areal unit problem, often abbreviated to MAUP.
Suppose we have thousands of individual observations.
We group them into geographical areas.
The statistical relationships we observe can change depending on:
- how large the areas are;
- where we draw their boundaries.
Imagine a city divided into:
[ 10 ]
large districts.
We might observe one relationship between income and transport use.
Divide the same city into:
[ 100 ]
smaller neighbourhoods and the relationship may look different.
Change the boundaries again and it may change again.
The underlying people have not changed.
Our representation of space has.
This means geographical boundaries are not always neutral containers for data.
They can affect the patterns we think we see.
Administrative boundaries are human inventions
Datasets are often organised according to convenient boundaries:
- countries,
- counties,
- states,
- municipalities,
- postcodes,
- census areas.
These are useful.
But the process being modelled may not care about those boundaries.
A river catchment does not necessarily follow political boundaries.
Air pollution crosses administrative borders.
Electricity flows according to electrical networks.
Traffic follows roads.
Disease spreads through interactions between people.
Economic activity follows supply chains, transport systems and markets.
So we should ask:
Does the geography in our dataset correspond to the geography of the system we are trying to understand?
Sometimes it does.
Sometimes it does not.
Interpolation
Suppose we have air-quality sensors at a limited number of locations.
We know pollution at:
[ s_1,s_2,\ldots,s_n ]
but want to estimate pollution at some location:
[ s^* ]
where there is no sensor.
We may use nearby observations to estimate:
[ \hat{y}(s^*) ]
This is spatial interpolation.
The basic idea is:
Use what we know about measured locations to estimate what may be happening between them.
Different methods make different assumptions about how smoothly conditions vary across space.
This can be extremely useful.
But every interpolation contains assumptions.
If a pollution source sits directly between two sensors, a smooth interpolation may completely miss it.
Spatial resolution
Imagine a satellite image where each pixel represents:
[ 1\text{ km}^2 ]
Now compare it with an image where each pixel represents:
[ 10\text{ m}\times10\text{ m} ]
The second dataset has much higher spatial resolution.
It can reveal smaller features.
But higher resolution also creates costs:
- more data,
- more computation,
- more storage,
- potentially more noise,
- greater privacy concerns.
More spatial detail is not automatically better.
The useful question is:
What resolution is necessary for the decision we are trying to make?
Spatial prediction and uncertainty
Just as forecasts across time should express uncertainty, spatial predictions should too.
Suppose we predict air pollution across a city.
Near measurement stations, we may have relatively high confidence.
Far from sensors, uncertainty may increase.
We might therefore have:
[ \hat{y}(s) ]
and:
[ \sigma(s) ]
where:
- (\hat{y}(s)) is the predicted value at location (s),
- (\sigma(s)) represents uncertainty at that location.
This means uncertainty itself can have a geography.
Some places may be well observed.
Others may be almost invisible to the measurement system.
Where sensors are located matters
Imagine a city installs 100 air-quality sensors.
Where should they go?
If all 100 sensors are placed in wealthy central neighbourhoods, the dataset may describe those locations extremely well.
But what about:
- industrial areas,
- poorer neighbourhoods,
- roads with heavy traffic,
- suburbs,
- areas near airports?
The resulting prediction model may perform differently across the city.
This returns us to something introduced much earlier in the course:
Data is created through systems of measurement.
Spatial data is therefore partly a record of where we chose to look.
Missing places
Suppose a healthcare dataset contains excellent information from large urban hospitals but very little information from rural clinics.
A model trained on that dataset may perform extremely well nationally on average.
But that average may conceal large geographical differences.
Similarly:
- satellite imagery may be obscured more often by cloud in some regions;
- mobile-phone data may represent connected populations better than disconnected ones;
- financial datasets may contain richer information in areas with greater banking access;
- electricity systems may have detailed sensors at high voltage but limited visibility deeper in distribution networks.
Missing data therefore has a spatial dimension.
Some places can be systematically better measured than others.
Geography can become a proxy
Location can also reveal much more than location.
A postcode might correlate with:
- income,
- ethnicity,
- education,
- health,
- property value,
- environmental exposure,
- political behaviour,
- access to services.
So even if a model does not explicitly receive a sensitive characteristic, geographical variables may act as proxies for it.
Imagine a lending model that does not use ethnicity.
It does use:
[ \text{postcode} ]
If postcode is strongly associated with historical patterns of segregation or deprivation, location may indirectly reproduce some of that information.
This does not mean geographical variables should never be used.
Location can be genuinely important.
But it means we need to understand what information geography may encode.
We will return to this when we examine AI, society, power and fairness.
Spatial bias can become self-reinforcing
Suppose a predictive policing system identifies neighbourhood A as having higher crime.
More police are sent there.
More police presence means more offences are observed and recorded.
The next dataset therefore contains more recorded crime in neighbourhood A.
The model is retrained.
It again predicts higher crime there.
More police are sent.
We now have a feedback loop:
[ \text{historical data} \rightarrow \text{prediction} \rightarrow \text{resource allocation} \rightarrow \text{new observations} \rightarrow \text{new data} ]
The prediction affects where we look.
Where we look affects what we observe.
What we observe becomes the next training dataset.
This makes spatial prediction particularly important when predictions determine the allocation of resources.
Maps are models
A map feels like an objective representation of reality.
But every map makes choices.
A map decides:
- what to include,
- what to exclude,
- where boundaries lie,
- what resolution to use,
- which features are important,
- how information is categorised.
The same is true of a spatial dataset.
Representing the world as:
[ \text{postcode areas} ]
is one model.
Representing it as:
[ 1\text{ km grid cells} ]
is another.
Representing it as:
[ \text{electricity network nodes} ]
is another.
Representing it as:
[ \text{road network intersections} ]
is another.
None is simply "the geography".
Each representation captures different relationships.
Graphs and networks
Sometimes the most useful representation of space is not a conventional map at all.
Consider an electricity grid.
We might represent it as a graph:
[ G=(V,E) ]
where:
- (V) represents nodes,
- (E) represents connections between nodes.
Now location is partly determined by network position.
The same representation can describe:
- roads,
- railways,
- telecommunications,
- social networks,
- supply chains,
- computer networks.
Prediction can then depend not simply on:
[ (x,y) ]
coordinates, but on relationships between connected entities.
This opens the door to methods such as graph neural networks, which we will encounter later.
Space and time interact
Many real forecasting problems are both spatial and temporal.
Traffic congestion changes:
- across roads,
- across cities,
- across time.
Electricity demand changes:
- across network locations,
- across time.
Weather changes:
- across geography,
- across time.
Disease spreads:
- between places,
- over time.
We might therefore want to predict:
[ P(Y_{s,t+h}\mid X) ]
for many locations (s) and future times (t+h).
This is spatiotemporal prediction.
Now the model needs to learn:
- temporal relationships,
- spatial relationships,
- interactions between the two.
A simple traffic example
Suppose congestion begins on Road A.
Five minutes later, vehicles divert onto Road B.
Ten minutes later, Road B becomes congested.
Traffic then spills onto Road C.
The pattern is neither purely spatial nor purely temporal.
It propagates:
[ (A,t) \rightarrow (B,t+5) \rightarrow (C,t+10) ]
A useful prediction model needs to understand how states move through the network over time.
Similar propagation occurs with:
- weather systems,
- electricity disturbances,
- infectious disease,
- supply-chain disruption,
- information on social networks.
Electricity is a spatiotemporal system
Electricity provides a particularly clear example.
At any moment, the system has:
- demand at different locations,
- generation at different locations,
- network constraints,
- power flows,
- storage states,
- renewable availability.
These conditions change continuously through time.
A prediction such as:
Demand will be 40 GW at 18:00.
therefore captures only a small part of the system state.
A richer prediction might be:
[ \hat{D}_{i,t} ]
for every network location (i) and time (t).
Now we can begin asking:
- where will demand occur?
- where will generation be available?
- where might congestion emerge?
- where might flexibility be valuable?
- where might network capacity become scarce?
The spatial distribution matters because electricity cannot simply teleport from wherever it exists to wherever it is needed.
The physical network constrains what is possible.
A national surplus can coexist with a local shortage
Suppose:
[ \text{national generation}=50\text{ GW} ]
and:
[ \text{national demand}=45\text{ GW} ]
At the aggregate level:
[ \text{supply}>\text{demand} ]
There appears to be a comfortable surplus.
But suppose a region requires:
[ 5\text{ GW} ]
while only:
[ 2\text{ GW} ]
can be supplied locally and the connecting network can import only:
[ 2\text{ GW} ]
Then available supply is:
[ 2+2=4\text{ GW} ]
against demand of:
[ 5\text{ GW} ]
The country can simultaneously have:
[ 5\text{ GW} ]
of aggregate surplus and:
[ 1\text{ GW} ]
of local shortage.
Both statements are true.
The difference is spatial resolution.
Prediction should respect physical constraints
Suppose an AI predicts electricity flows.
It predicts that:
[ 3\text{ GW} ]
will move through a transmission line capable of carrying only:
[ 2\text{ GW} ]
The prediction may be statistically plausible based on historical patterns.
But physically it cannot happen.
This introduces another important idea:
Predictions about physical systems should ideally respect the constraints of those systems.
For an electricity network, these might include:
- line capacities,
- voltage limits,
- power balance,
- generator limits.
For traffic:
- road capacity,
- direction of travel,
- network connectivity.
For water:
- pipe capacities,
- reservoirs,
- flow constraints.
Spatial prediction increasingly meets physics.
Local versus global models
Suppose we want to forecast electricity demand across 1,000 regions.
One approach is to build:
[ 1000 ]
separate local models.
Each model learns only from its own area.
Another approach is to build one global model using data from all locations.
The global model may learn common patterns:
- morning demand increases,
- temperature effects,
- weekday behaviour.
But local areas may also have unique characteristics.
A good model may therefore need to learn both:
[ \text{shared structure} + \text{local structure} ]
This tension between local and global information appears throughout machine learning.
Spatial generalisation
Suppose we train a model using data from:
- Dublin,
- London,
- Paris.
Will it work in:
- Nairobi?
Perhaps.
But perhaps not.
The relationship between inputs and outcomes may differ because of:
- climate,
- infrastructure,
- culture,
- income,
- urban form,
- regulation,
- behaviour.
This creates a spatial version of the generalisation problem.
A model may perform well in locations represented in its training data but poorly somewhere genuinely new.
We therefore need to ask:
Can this model generalise across space?
as well as:
Can it generalise across time?
Spatial train-test splitting
This has consequences for model evaluation.
Suppose we randomly divide individual observations into training and test sets.
Neighbouring observations may appear in both.
Because nearby locations are often similar, the model may appear extremely accurate.
But perhaps our real task is predicting conditions in entirely new locations.
A better evaluation might hold out whole regions.
For example:
Training
Regions A, B, C and D.
Testing
Region E.
Now we are asking a much harder question:
Can the model generalise to a place it has not previously observed?
The correct evaluation design depends on the intended use.
Spatial leakage
Just as information can leak through time, it can leak through space.
Suppose we want to predict pollution at a location.
A sensor:
[ 10\text{ metres} ]
away is included as an input.
The model performs brilliantly.
But suppose the deployed system is intended to predict pollution in regions where the nearest sensor is:
[ 20\text{ kilometres} ]
away.
The test conditions did not represent the real problem.
Again, impressive accuracy can result from an unrealistic evaluation setup.
The question is always:
What information will genuinely be available when and where the model is deployed?
Geography is not static either
Spatial systems change over time.
New roads are built.
Electricity networks are reinforced.
Neighbourhoods change.
Hospitals open and close.
Populations move.
Land use changes.
Climate alters environmental conditions.
So even our representation of space may evolve:
[ G_t \neq G_{t+10} ]
where (G_t) represents the network or geography at time (t).
Spatial prediction therefore eventually becomes inseparable from forecasting across time.
The world changes both:
[ \text{when} ]
and:
[ \text{where} ]
From prediction to allocation
Spatial prediction becomes especially consequential when it determines where resources go.
Suppose an AI predicts demand for ambulances.
It might estimate:
[ P(\text{emergency call}\mid s,t) ]
across a city.
Those predictions could determine where ambulances are positioned.
Now the model is influencing the spatial distribution of a scarce resource.
The same could apply to:
- police,
- hospital capacity,
- electricity flexibility,
- public transport,
- road investment,
- broadband infrastructure,
- schools,
- emergency services.
At this point, the question is no longer simply:
Where will demand occur?
It becomes:
Given where demand may occur, how should limited resources be distributed?
That is an allocation problem.
Prediction can reshape geography
Suppose a navigation system predicts congestion.
It routes thousands of drivers away from one road.
Those drivers enter surrounding streets.
The spatial pattern of congestion changes.
Again:
[ \text{prediction} \rightarrow \text{decision} \rightarrow \text{action} \rightarrow \text{changed spatial state} ]
The same phenomenon can occur when:
- investors respond to house-price predictions,
- police respond to crime predictions,
- businesses respond to demand forecasts,
- electricity assets respond to local price forecasts.
Once predictions influence behaviour, the map we are predicting begins responding to the prediction itself.
The deeper lesson
Earlier in the course, we introduced the idea:
The future does not exist yet.
Spatial prediction adds another important observation:
There is no single state of the world that exists independently of where we look.
The same system can appear:
- balanced nationally,
- constrained regionally,
- overloaded locally.
The same model can appear:
- accurate globally,
- inaccurate locally.
The same population can exhibit different statistical relationships depending on:
- spatial resolution,
- geographical boundaries,
- network representation.
So prediction is not merely:
[ \text{what?} ]
It is:
[ \text{what?} + \text{when?} + \text{where?} ]
And increasingly:
[ \text{connected to what?} ]
A useful representation of prediction therefore becomes:
[ P(Y_{s,t+h}\mid\mathcal{I}_t,G) ]
where:
- (s) represents location,
- (t+h) represents the future time,
- (\mathcal{I}_t) represents the information currently available,
- (G) represents relevant spatial or network relationships.
This brings together much of what we have learned.
We observe the past at particular places and times.
We construct models from those observations.
We use them to infer possible future states across space.
Those predictions inform decisions.
Those decisions allocate resources.
And those allocations change the spatial and temporal state of the world that generates the next dataset.
So whenever you see a prediction, ask not merely:
How accurate is it?
Ask:
Accurate where?
At what spatial resolution?
According to which boundaries?
What relationships between places does the model understand?
Which places are well measured, and which are almost invisible?
Does aggregation hide local failures?
And, once the prediction begins informing real decisions:
Who receives resources because of this spatial prediction — and who does not?