📖 Scenario: You are learning how AI systems learn from examples. Imagine you want to teach a simple AI to recognize fruits based on their color and size.
🎯 Goal: Build a simple data set of fruits, set a rule to decide if a fruit is 'likely an apple', and apply that rule to classify the fruits.
📋 What You'll Learn
Create a dictionary called fruits with fruit names as keys and their attributes as values (color and size).
Create a variable called apple_color and set it to the string 'red'.
Use a dictionary comprehension called apple_likelihood to mark fruits as true if their color matches apple_color and size is 'medium'.
Add a final statement to count how many fruits are likely apples and store it in apple_count.
💡 Why This Matters
🌍 Real World
Understanding how AI uses training data helps in designing fair and accurate AI systems in areas like image recognition and recommendation engines.
💼 Career
This knowledge is important for roles in AI development, data science, and machine learning engineering where data quality directly affects AI behavior.
Progress0 / 4 steps
1
Create the fruit data set
Create a dictionary called fruits with these exact entries: 'banana': {'color': 'yellow', 'size': 'medium'}, 'apple1': {'color': 'red', 'size': 'medium'}, 'apple2': {'color': 'green', 'size': 'small'}, 'cherry': {'color': 'red', 'size': 'small'}.
AI for Everyone
Hint
Use a dictionary with fruit names as keys and another dictionary for their color and size.
2
Set the apple color to look for
Create a variable called apple_color and set it to the string 'red'.
AI for Everyone
Hint
Assign the string 'red' to the variable apple_color.
3
Identify likely apples using a dictionary comprehension
Create a dictionary comprehension called apple_likelihood that goes through fruits.items() and sets the value to true if the fruit's color equals apple_color and its size is 'medium', otherwise false.
AI for Everyone
Hint
Use a dictionary comprehension with for fruit, info in fruits.items() and check both color and size.
4
Count how many fruits are likely apples
Create a variable called apple_count that sums the true values in apple_likelihood.values().
AI for Everyone
Hint
Use the sum() function on the values of apple_likelihood to count true entries.
Practice
(1/5)
1. Why is training data important for AI behavior?
easy
A. Because training data controls the hardware AI runs on
B. Because training data is used to write AI's code manually
C. Because training data is only used after AI is fully built
D. Because AI learns patterns from training data to make decisions
Solution
Step 1: Understand AI learning process
AI learns by finding patterns in examples called training data.
Step 2: Connect training data to AI decisions
Good training data helps AI make better decisions by showing it what to expect.
Final Answer:
Because AI learns patterns from training data to make decisions -> Option D
Quick Check:
Training data shapes AI behavior = C [OK]
Hint: AI learns from examples, not from code or hardware [OK]
Common Mistakes:
Thinking AI code is written from training data
Confusing training data with hardware
Believing training data is used after AI is built
2. Which of these is the correct way to describe training data's role?
easy
A. Training data is the set of examples AI uses to learn
B. Training data is the AI's final output after learning
C. Training data is the software that runs AI models
D. Training data is the hardware AI uses to process information
Solution
Step 1: Define training data
Training data is the collection of examples given to AI to learn from.
Step 2: Eliminate incorrect options
Training data is not output, software, or hardware but input examples.
Final Answer:
Training data is the set of examples AI uses to learn -> Option A
Quick Check:
Training data = learning examples [OK]
Hint: Training data = examples AI learns from, not output or hardware [OK]
Common Mistakes:
Confusing training data with AI output
Mixing training data with software or hardware
Thinking training data runs the AI
3. Consider this code snippet simulating AI training data influence:
training_data = ['cat', 'dog', 'cat', 'bird']
model_behavior = {animal: training_data.count(animal) for animal in set(training_data)}
print(model_behavior)
What is the output?
medium
A. {'cat': 1, 'dog': 1, 'bird': 1}
B. {'cat': 2, 'dog': 1, 'bird': 1}
C. {'cat': 3, 'dog': 1, 'bird': 1}
D. Error: count method not found
Solution
Step 1: Understand the code logic
The code counts how many times each unique animal appears in training_data.
Step 2: Count occurrences
'cat' appears twice, 'dog' once, 'bird' once, so the dictionary reflects these counts.
Final Answer:
{'cat': 2, 'dog': 1, 'bird': 1} -> Option B
Quick Check:
Count of each animal in list = {'cat': 2, 'dog': 1, 'bird': 1} [OK]
Hint: Count items in list using count() for each unique element [OK]
Common Mistakes:
Assuming count counts total list length
Confusing set with list order
Thinking count method causes error
4. This code tries to count training data items but has a bug:
training_data = ['apple', 'banana', 'apple']
model_behavior = {animal: training_data.count for animal in set(training_data)}
print(model_behavior)
What is the error and how to fix it?
medium
A. Error: set() cannot be used on lists
B. Error: print() cannot display dictionaries
C. Error: count is a method, should be called with parentheses like count()
D. No error, code runs fine
Solution
Step 1: Identify the bug in code
The code uses training_data.count without parentheses, so it refers to the method itself, not calling it.
Step 2: Fix the method call
Adding parentheses and argument fixes it: training_data.count(animal)
Final Answer:
Error: count is a method, should be called with parentheses like count() -> Option C
Quick Check:
Method call missing parentheses = B [OK]
Hint: Remember to call methods with () to execute them [OK]
Common Mistakes:
Thinking set() can't be used on lists
Believing print can't show dictionaries
Ignoring missing parentheses on method calls
5. An AI model trained only on photos of cats and dogs struggles to recognize birds. What is the best way to improve its behavior?
hard
A. Add more bird photos to the training data
B. Remove all cat and dog photos from training data
C. Change the AI model architecture without changing data
D. Train the AI only on bird photos
Solution
Step 1: Identify the problem with training data
The model lacks examples of birds, so it cannot learn to recognize them well.
Step 2: Improve training data quality
Adding bird photos gives the AI examples to learn bird features, improving recognition.
Final Answer:
Add more bird photos to the training data -> Option A
Quick Check:
More diverse training data = better AI behavior [OK]
Hint: Add missing examples to training data to improve AI [OK]
Common Mistakes:
Removing existing data reduces AI knowledge
Changing model without data won't fix missing knowledge
Training only on birds loses knowledge of cats and dogs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.