0
0
AI for Everyoneknowledge~30 mins

Machine learning vs rule-based systems in AI for Everyone - Hands-On Comparison

Choose your learning style9 modes available
Machine learning vs rule-based systems
📖 Scenario: You are working on a simple AI assistant that can decide how to respond to user questions. You want to understand the difference between machine learning and rule-based systems by creating examples of each.
🎯 Goal: Build two simple examples: one using a rule-based system with fixed rules, and one using a machine learning style approach with data and a simple decision logic. This will help you see how each system works in practice.
📋 What You'll Learn
Create a dictionary called rules with fixed question-answer pairs
Create a list called training_data with example questions and answers
Write a function called rule_based_response that uses the rules dictionary to find answers
Write a function called ml_style_response that uses simple matching on training_data to find answers
💡 Why This Matters
🌍 Real World
Understanding the difference between rule-based and machine learning systems helps when designing AI assistants, chatbots, or decision-making software.
💼 Career
Many AI and software development jobs require knowledge of how to implement and choose between rule-based logic and machine learning models.
Progress0 / 4 steps
1
DATA SETUP: Create the rule-based system dictionary
Create a dictionary called rules with these exact entries: 'hello': 'Hi there!', 'bye': 'Goodbye!', and 'thanks': 'You are welcome!'.
AI for Everyone
Hint

Use curly braces {} to create a dictionary with keys and values.

2
CONFIGURATION: Create the machine learning style training data
Create a list called training_data with these exact tuples: ('hello', 'Hi there!'), ('bye', 'Goodbye!'), and ('thanks', 'You are welcome!').
AI for Everyone
Hint

Use square brackets [] to create a list of tuples.

3
CORE LOGIC: Write the rule-based response function
Write a function called rule_based_response that takes a parameter question and returns the answer from the rules dictionary if the question exists, or 'I do not understand.' if it does not.
AI for Everyone
Hint

Use an if statement to check if the question is a key in the rules dictionary.

4
COMPLETION: Write the machine learning style response function
Write a function called ml_style_response that takes a parameter question and searches the training_data list for a matching question. If found, return the answer; otherwise, return 'I do not understand.'. Use a for loop with variables q and a to iterate over training_data.
AI for Everyone
Hint

Use a for loop to check each tuple in training_data for a matching question.