Bread and milk, together
A made-up corner shop looks at six shopping baskets. Bread and milk keep turning up together. Nobody told the shop to look for that pair. It simply showed itself.
Finding patterns nobody asked about is one kind of predictive work. Today we meet it, and a second kind: trying the future out on a computer.
Key words
| Word | What it means | Example |
|---|---|---|
| Data mining | Searching a large amount of data for patterns nobody asked for. | Items often bought together |
| Market basket analysis | Data mining that finds which items are bought in the same basket. | Bread and milk |
| Simulation | A computer model that runs a made-up situation many times to see the range of results. | Two hundred pretend days of demand |
| Random number | A number picked with no pattern you can predict. | A dice roll |
| Seed | The starting number a random number maker uses. The same seed gives the same run. | 7 |
| Forecast | An estimate of a future value, based on the past. | Next week's sales |
| Predictive analytics | Using data to say what is likely to happen. | Forecasts, simulations and mining |
The cells students fill in are left blank in this preview.
By the end of this lesson
Note
I can explain data mining and market basket analysis, run a simulation, and say how a forecast differs from both.
Starter: last lesson
Have a go
Starter: last lesson
3 questionsYour answers are marked here and are not kept. A college account keeps every student’s marks.
Data mining: find what nobody asked for
Data mining searches a large amount of data for patterns. You do not start with a question. The pattern is the answer.
Market basket analysis is the best known kind. It counts how often two items are bought together. A shop can then put them near each other, or offer a deal on the pair.
Worked example: six baskets, three pairs
| Pair | Baskets with both | Baskets with the first item | Reading |
|---|---|---|---|
| Bread and milk | 4 | 5 have bread | Of 5 bread baskets, 4 also have milk |
| Bread and jam | 3 | 5 have bread | Of 5 bread baskets, 3 also have jam |
| Milk and tea | 2 | 5 have milk | Of 5 milk baskets, 2 also have tea |
The cells students fill in are left blank in this preview.
Try it: count the pairs
select a.item as item_a, b.item as item_b, count(*) as together
from baskets a
join baskets b on a.basket_id = b.basket_id and a.item < b.item
group by a.item, b.item
order by together desc, item_a, item_b;
-- The join pairs every two items in the same basket. a.item < b.item stops a pair counting twice.Simulation: try the future out
A simulation runs a made-up situation many times, with a random number each time. It shows the range of what could happen.
The bakery bakes 85 loaves. Demand each day is a random number from 60 to 100. Run 200 pretend days and count how often it runs short. A computer makes random numbers from a seed. The same seed gives the same run.