Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Patterns and Predictions
The goal of machine learning is to find patterns in training data that are useful for making predictions on new data. Understanding what a pattern is in AI helps you understand what these systems are actually doing.
What is a Pattern in AI?
A pattern in AI is a consistent relationship between features and labels found across many examples.
Examples of patterns:
- In house price data: larger houses consistently sell for more money
- In email data: emails with more uppercase letters and the word 'FREE' are more likely to be spam
- In medical data: patients with certain combinations of symptoms more often have a specific diagnosis
The AI finds these patterns by looking at many examples and measuring what features tend to be associated with which labels.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
From Pattern to Prediction
Once the AI has found a pattern, it can make predictions on new data it has never seen.
Here is the process:
1. AI studies 10,000 email examples and finds: emails with words like 'free', 'win', 'prize' tend to be spam
2. New email arrives: 'Congratulations! You won a free prize!'
3. AI recognizes this matches the spam pattern
4. AI predicts: spam
The AI does not need a human to tell it the rule. It discovered the rule from data.
Simple Pattern Finding
# Let's find a simple pattern in temperature and ice cream sales
# (Illustrative data for learning)
data = [
# (temperature_celsius, ice_cream_sales_units)
(15, 30),
(20, 50),
(25, 75),
(30, 110),
(35, 145),
(40, 180),
]
# Find the pattern: as temperature increases, what happens to sales?
print("Looking for a pattern in the data:")
print()
for temp, sales in data:
bar = "#" * (sales // 5)
print(f" {temp}C: {sales:3d} units {bar}")
print()
# Calculate the average increase per degree
temperatures = [row[0] for row in data]
sales = [row[1] for row in data]
total_temp_change = temperatures[-1] - temperatures[0]
total_sales_change = sales[-1] - sales[0]
rate = total_sales_change / total_temp_change
print(f"Pattern found: approximately {rate:.1f} more ice creams sold per degree Celsius")
print()
# Use the pattern to make a prediction
new_temp = 28
predicted_sales = 30 + (new_temp - 15) * rate
print(f"Prediction: at {new_temp}C, expect approximately {predicted_sales:.0f} ice creams sold")Tip
Tip
Real AI patterns are much more complex than temperature vs. sales. An image recognition model might use millions of pixel values as features. But the core idea is the same: find consistent relationships between inputs and outputs across many examples.