Understanding AI · lesson 9 of 60 · about 5 minutes
Patterns in Numbers
Before AI can predict anything, it needs a pattern. Find the trend hiding in a list of numbers.
What you'll learn
- Find a trend in a set of examples
- Work out an average
- Explain why AI looks for patterns
A pattern is a rule you discover
Look at ice cream sales on days of different temperatures. Hotter days, more sales. Nobody wrote that rule down; it shows up in the data.
Finding patterns like this is what machine learning does, just with far more examples and far more features than a person could check.
Ice creams sold on four days. `zip` walks through two lists side by side.
temperatures = [15, 20, 25, 30]
sales = [30, 50, 70, 90]
for t, s in zip(temperatures, sales):
print(t, "degrees:", s, "sold")Output
15 degrees: 30 sold
20 degrees: 50 sold
25 degrees: 70 sold
30 degrees: 90 soldAverages
The simplest summary of some numbers is the average: add them up and divide by how many there are. AI uses averages all the time, for example to say what's typical.
`sum()` adds up a list; `len()` counts it.
sales = [30, 50, 70, 90]
average = sum(sales) / len(sales)
print(average)Output
60.0Now try it yourself
This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.