Imagine it's a Friday morning. You need to buy groceries for the weekend. There are three supermarkets in your area: one right next door, but it's small with an uninspired selection; a second, larger one, but it's a twenty-minute drive away; and a third, a proper hypermarket with a vast selection, but getting there means crossing the entire city. Which one do you choose?
Most likely, you won't be running equations in your head. You'll just feel that one option is better than another. But if you were to break down exactly what you're weighing, you'd find a genuine mathematical model at work in your mind. And it has a name: the Huff model.
David Huff formulated it in 1964, and it hasn't lost its relevance since. In fact, it has become one of the primary tools for anyone deciding where to open a store, clinic, or school. And now, in the 2020s, it has been implemented as an open-source Python package called huff. This is the tool we'll be discussing – but we'll start, as always, with the core concept: the idea.
Gravity in the World of Shopping 🛒
Isaac Newton described gravity this way: two bodies attract each other more strongly the more massive they are, and more weakly the farther apart they are. David Huff applied the same logic to people and stores. It might sound strange, but it works surprisingly well.
In his model, a store's “mass” is its attractiveness: its floor space, product range, and reputation. And “distance” isn't just kilometers, but also travel time, traffic, and inconvenient transfers. The more attractive a store is and the closer it is, the higher the probability that you'll end up there this Friday.
The key word here is probability. The Huff model doesn't say, “This consumer will go to store A.” It says, “This consumer has a 60% probability of choosing store A, a 30% probability of choosing store B, and a 10% probability of choosing store C.” This is more honest because real people are unpredictable. But if you take thousands of people, the math begins to work impeccably: 60% of them will indeed end up at store A.
I promised a minimum of formulas – and I'll keep my word. But there's one principle I need to explain because it's precisely what makes the model so powerful.
Imagine each store has a kind of “pull” – a number that depends on two things: how good the store is and how far away it is. Attractiveness pulls the consumer toward the store, while distance pushes them away. The probability of visiting a particular store is its “pull” divided by the sum of the “pulls” of all competing stores in the vicinity. This means the model always evaluates a store not in isolation, but in comparison with its competitors.
This logic involves two numerical parameters that tune the model to reality. One governs how important attractiveness is: do people drive thirty kilometers for a huge shopping mall, or do they prefer a modest but nearby store? The second governs sensitivity to distance: how quickly does a consumer's interest wane as travel time increases? In a city with good transportation, people are willing to travel farther. In a region where getting anywhere is a challenge, even an extra five kilometers can dramatically decrease the probability of a trip.
These parameters aren't just invented – they are estimated from real data. If we have data on where people have shopped in the past, the model can adjust its parameters to most accurately replicate that observed behavior. It can then be used for prediction: what will change if we open a new store? Or close an old one? Or improve a road?
Every store, every hospital, every school has its “zone of influence” – a territory whose residents are most likely to use that specific facility. This is called a service area, or a catchment area.
Interestingly, these zones don't have clear-cut borders. Unlike administrative districts drawn with straight lines on a map, real zones of influence are fuzzy, overlapping, and cloud-like. Someone living on the border of two zones might be equally likely to travel to either of the two nearest supermarkets. This is the mathematics of the Huff model: not rigid boundaries, but smooth probabilities.
This is precisely why the model is so useful for planning. If you simply draw rigid circles around a store on a map and assume everyone inside is your customer and everyone outside is not, you are making a big mistake. Reality is much more nuanced. And the Huff model captures that nuance.
So far, we've been talking about stores and shoppers. But the same logic applies in a completely different context – one where the stakes are significantly higher.
Imagine a region where you need to assess how well the population is served by healthcare. Where is there a shortage of doctors? Which areas are effectively cut off from clinics due to poor roads or long distances? Where should a new hospital be opened so that it helps the maximum number of people, rather than just duplicating the services of existing facilities?
These are problems of spatial accessibility. And the Huff model handles them just as effectively as it does retail analysis. The only difference is that instead of a store's floor space, we might use the number of doctors or hospital beds, and instead of the desire to buy a product, we consider the population's need for healthcare.
A special approach has been developed for this type of analysis, called the Two-Step Floating Catchment Area (or 2SFCA). The name sounds intimidating, but the idea is simple. In the first step, we look at each clinic and calculate how many people are within its reach. In the second step, we look at each residential area and sum up the accessibility of all the clinics it can reach. The result is a map showing where healthcare is accessible and where people are living in “care deserts” without adequate services nearby.
Maps like these are not just an abstraction. They help inform real decisions about where to allocate resources, where to build new facilities, and how to redistribute the load among existing ones.
The mathematics we've described has been around for six decades. But to apply it in practice, you need data, computational power, and the skill to connect all the pieces. This is precisely why the Python package huff was created – an open-source tool available through the standard Python package repository (PyPI) and maintained in an open repository on GitHub.
Let's walk through what this package can do – without any programming code, just step-by-step.
Step One: Data on People and Places
To start, you need to know two things: where people live and where the facilities (stores, hospitals, schools) are located. People can be described by geographic areas, like city districts, along with their population counts. Facilities can be represented as points on a map with an indicator of their attractiveness (floor space, number of doctors, or any other capacity metric).
The huff package works with geospatial data in standard formats compatible with GeoPandas – one of the most popular Python libraries for working with geographic data. This means you can load almost any common geospatial data format, such as Shapefile, GeoJSON, and others.
Step Two: The Cost Matrix
Next, we need to figure out how far each residential area is from each facility. The output is a table: rows represent the residential areas, columns represent the facilities, and the cells contain the travel time or distance. This is called a cost matrix.
The huff package can build this matrix in several ways. The simplest is by calculating the straight-line distance, “as the crow flies,” as if the terrain were perfectly flat with no roads. This is suitable for rough estimates. A more realistic method is to use the actual road network from open data sources like OpenStreetMap. In that case, the matrix will account for real routes, detours, and dead ends.
Step Three: Running the Model
Now, the Huff model itself comes into play. The package takes the data on people, the data on facilities, and the cost matrix – and calculates the probabilities. Each residential area is assigned a set of probabilities: the likelihood that residents from that area will travel to each of the facilities.
If we have real-world data on people's behavior – for example, travel data – the package can automatically adjust the model's parameters to best replicate the observed reality. This is called model calibration, and it's a critically important step: a model that hasn't been tuned for a specific region can yield heavily skewed results.
Step Four: Visualizing the Results
Numbers in tables are fine. But a map is more convincing than a hundred tables. The huff package can generate several types of maps:
- Market share maps – show what portion of the consumer flow each facility captures from each area.
- Accessibility maps – show how well each area is served by facilities (especially useful for healthcare and social services).
- Flow diagrams – visualize the direction and intensity of consumer movement from residential areas to facilities.
All of this is built using standard Python visualization libraries – Matplotlib and GeoPandas – which means it's fully compatible with the typical workflows of analysts and researchers.
Three Stories of How It Works in Real Life
Story One: Where to Place a New Store
Imagine a retail chain planning to open a new location in a large city. They already have several stores and want to expand – but without “cannibalizing” their own customer base. After all, if a new store opens too close to an existing one, it will simply attract the same customers instead of bringing in new ones. This effect is known as cannibalization.
Using the Huff model, they can simulate several potential locations for the new store and compare how the distribution of customer flow would change in each scenario. Where will the new store expand the company's reach? Where will it merely redistribute existing customers? The result isn't a guess, but a mathematically justified choice.
Story Two: Blank Spots on the Healthcare Map
A regional health department wants to understand where residents are facing a shortage of medical care. They know how many doctors work in each clinic and where the population lives. But how can they connect these two sets of data?
Using the 2SFCA method implemented in the huff package, they can calculate an accessibility index for each area. The map will immediately show which areas are well-served and which are “healthcare deserts,” where the nearest clinic is too far away and serves too many people. This provides a direct guide for action: a new clinic should be built here, not there.
Story Three: Marketing with Spatial Intelligence
Marketers at a large shopping center want to understand how an advertising campaign will affect their market share. The logic is as follows: a successful ad campaign increases the perceived attractiveness of the facility in the eyes of consumers. This can be modeled by simply increasing the attractiveness parameter in the Huff model and recalculating the probabilities. The results will show which areas the shopping center will gain customers from and at which competitors' expense.
This isn't magic. It's mathematics put to the service of common sense.
Why This Matters: Spatial Thinking as a Skill
We are used to thinking of data in terms of tables and charts. But data also exists in space. Every person lives somewhere. Every store is located somewhere. The distance between them isn't an abstraction; it's a real barrier or an opportunity.
The Huff model and tools like the huff package remind us of this. They tell us: before making a decision, look at the map. Don't just draw a circle and say, “this is our catchment area.” Ask what the probability is that each person within that circle will actually choose you over a competitor. Consider the distance. Consider the attractiveness. Consider the competition.
The huff package is an open-source tool available to any researcher, planner, or analyst. It is designed for specialists in economic geography, regional planning, marketing, and public health. But its logic is universal: wherever people make choices between different locations, spatial mathematics comes into play.
Data doesn't lie. It whispers in a language that we need to learn to hear. And a map is one of the best translators.