Chapter 1: Introduction to Machine Learning / Lesson 2

What is AI and ML?

Understanding AI and Machine Learning

Artificial Intelligence (AI) and Machine Learning (ML) are often used interchangeably, but they're not the same thing. Understanding the relationship between them is crucial for your ML journey.

AI is the broader field—any technique that enables machines to mimic human intelligence. ML is a subset of AI that focuses on learning from data.

The Relationship: AI ⊃ ML

Think of it like this: AI is the umbrella, and ML is one approach under it. Not all AI uses ML, but most modern AI does:

ai_vs_ml.py
# Understanding AI vs ML # AI (Artificial Intelligence) - Broad field ai_techniques = { "Rule-based Systems": "Traditional AI with explicit rules", "Machine Learning": "Learn from data (subset of AI)", "Expert Systems": "Knowledge-based systems", "Search Algorithms": "Pathfinding, game AI" } print("AI Techniques (Broader Field):") for technique, description in ai_techniques.items(): print(f" {technique}: {description}") print("\n" + "=" * 50) print("Machine Learning (Subset of AI):") print(" - Learns patterns from data") print(" - Improves with experience") print(" - Makes predictions on new data") print("\nKey Point: All ML is AI, but not all AI is ML!")

Traditional AI vs Machine Learning

Traditional AI uses explicit rules, while ML learns from data:

traditional_ai_vs_ml.py
# Traditional AI: Explicit Rules def traditional_ai_classifier(temperature): # Human writes explicit rules if temperature > 25: return "Hot" elif temperature > 15: return "Warm" else: return "Cold" print("Traditional AI (Explicit Rules):") print(f" 30°C: {traditional_ai_classifier(30)}") print(f" 20°C: {traditional_ai_classifier(20)}") print(f" 10°C: {traditional_ai_classifier(10)}") print("\n" + "=" * 40) # Machine Learning: Learn from Data # Training data: (temperature, label) training_data = [ (30, "Hot"), (28, "Hot"), (20, "Warm"), (18, "Warm"), (10, "Cold"), (5, "Cold") ] print("Machine Learning (Learn from Data):") print("Training Examples:") for temp, label in training_data: print(f" {temp}°C → {label}") print("\nML algorithm learns the pattern from examples!") print("No explicit rules needed - it discovers them!")

Why Machine Learning Matters

ML has become the dominant approach in AI because it can handle problems that are too complex for rule-based systems:

why_ml_matters.py
# Why ML is Powerful problems = { "Image Recognition": { "rule_based": "Impossible - too many rules needed", "ml_approach": "Learn from millions of images" }, "Language Translation": { "rule_based": "Millions of grammar rules needed", "ml_approach": "Learn patterns from text pairs" }, "Recommendation Systems": { "rule_based": "Can't capture user preferences", "ml_approach": "Learn from user behavior" } } print("Why ML is Better for Complex Problems:") for problem, approaches in problems.items(): print(f"\n{problem}:") print(f" Rule-based: {approaches['rule_based']}") print(f" ML Approach: {approaches['ml_approach']}")

Deep Learning: ML's Powerful Subset

Deep Learning is a subset of ML that uses neural networks with many layers. The hierarchy is: AI ⊃ ML ⊃ Deep Learning

ai_hierarchy.py
# The AI Hierarchy hierarchy = { "Artificial Intelligence": { "description": "Broadest: Any technique for intelligent machines", "examples": ["Rule-based systems", "Search algorithms", "ML"] }, "Machine Learning": { "description": "Subset of AI: Learn from data", "examples": ["Linear regression", "Decision trees", "Deep Learning"] }, "Deep Learning": { "description": "Subset of ML: Neural networks with many layers", "examples": ["CNNs for images", "RNNs for text", "Transformers"] } } print("AI Hierarchy:") print("AI (Broadest)") print(" └── ML (Subset)") print(" └── Deep Learning (Subset of ML)") print("\n" + "=" * 50) for field, info in hierarchy.items(): print(f"\n{field}:") print(f" {info['description']}") print(f" Examples: {', '.join(info['examples'])}")

Real-World Examples

Here's how AI, ML, and Deep Learning appear in real applications:

real_world_examples.py
# Real-World Examples applications = { "Chess AI (Traditional AI)": { "type": "AI (not ML)", "method": "Search algorithms, minimax" }, "Email Spam Filter (ML)": { "type": "ML", "method": "Learns from spam/not-spam examples" }, "Image Recognition (Deep Learning)": { "type": "Deep Learning", "method": "Neural networks with many layers" } } print("Real-World AI/ML Applications:") for app, details in applications.items(): print(f"\n{app}:") print(f" Type: {details['type']}") print(f" Method: {details['method']}")

📝 Exercise: Build a Temperature Classifier

Complete the exercise in the code editor on the right. You'll practice:

  • Part 1: Complete the traditional_classifier function using explicit rules
  • Part 2: Analyze the training data to discover the pattern that ML would learn

For the classifier function, use these rules: if temp > 25 return "Hot", if temp > 15 return "Warm", otherwise return "Cold". Then analyze the training data to see what pattern ML would discover!

💡 Key Takeaway

AI is the goal (intelligent machines), ML is a method (learning from data), and Deep Learning is a powerful technique within ML. Most modern AI applications use ML because it can handle complexity that rule-based systems cannot!

🎉

Lesson Complete!

Great work! Continue to the next lesson.

main.py
📤 Output
Click "Run" to execute...