AI Lab 02: Neural Networks & Decision Boundaries with TensorFlow Playground
- Estimated Time: 5 hours
- Tools Required: TensorFlow Playground (Completely free, runs directly in your browser, no-code)
- Hardware Required: A computer with an internet connection.
Lab Objectives
- Understand the basic components of a Neural Network: Inputs (Features), Hidden Layers, Neurons, and Outputs.
- Observe how an AI learns to separate (classify) different groups of data by drawing "Decision Boundaries."
- Core Task: Through trial and error, discover why simple data can be separated by a straight line, while complex data requires deeper networks (more layers) and engineered features.
5-Hour Schedule & Step-by-Step Breakdown
Phase 1: Understanding the UI & Setup (0.5 Hour)
Phase 1: Understanding the UI & Setup (0.5 Hour)
- Open your browser and navigate to TensorFlow Playground.
- Familiarize yourself with the interface from left to right:
- DATA (Far Left): You can choose 4 different datasets (Gaussian/Blobs, Circle, XOR, and Spiral).
- FEATURES (Inputs): X1 represents the horizontal position of a data point, and X2 represents the vertical position.
- HIDDEN LAYERS (Middle): This is the "brain" of the AI. You can add layers (+) and add neurons to each layer (+).
- OUTPUT (Far Right): The final graph showing how the AI decides to color the background (blue vs. orange) to separate the dots.
- PLAY BUTTON (Top Left): Click this to start the training (watch the "Epoch" counter go up).
Phase 2: The Three Classification Experiments (3 Hours)
Phase 2: The Three Classification Experiments (3 Hours)
This phase requires you to test three distinct datasets with different network architectures.
Experiment 1: The Simple Blobs (0.5 Hour)
- Select the Data: Click the Gaussian dataset icon
(two separate clusters of dots). - Network Setup: * Set Hidden Layers to 0 (Remove all hidden layers using the - button).
- Keep only X1 and X2 as your features.
- Train: Click the Play button.
- Observe: Notice how the AI instantly draws a single, perfectly straight line to separate the orange dots from the blue dots. Take a screenshot when the training stabilizes.
Experiment 2: The Circle Challenge (1 Hour)
- Select the Data: Click the Circle dataset icon
(a blue circle surrounded by an orange ring). - The Failure Test: Keep the same setup as Experiment 1 (0 Hidden Layers, only X1 and X2). Click Play. You will notice the AI fails entirely because a straight line cannot trap a circle.
- The Solution (Adding Layers): * Add 1 Hidden Layer with 3 Neurons.
- Click Play. Watch how the three neurons create three straight lines that fold together to form a triangle, effectively trapping the inner circle!
- Experiment: Try increasing it to 4 or 5 neurons and see how the shape becomes a smoother polygon. Take a screenshot of a successful classification.
Experiment 3: The Ultimate Spiral (1.5 Hours)
- Select the Data: Click the Spiral dataset icon
(the notoriously difficult Spiral). - The Challenge: Try to get the "Test loss" (top right) below 0.05. This will not be easy!
- Exploration: * Add more Hidden Layers (try 3 or 4 layers).
- Add more Neurons to each layer.
- Feature Engineering: Check the boxes for advanced features on the left, like X12 (X1 squared), X22
- Observe: Click Play. This might take hundreds of Epochs. Watch the background slowly morph, bend, and twist until it learns the spiral pattern. Take a screenshot of your most successful (or most bizarre) spiral boundary.
Phase 3: Writing the AI Lab Journal (1.5 Hours)
Phase 3: Writing the "AI Lab Journal" (1.5 Hours)
Complete an "AI Lab Journal" in a Word or Markdown file. This will serve as tangible proof of your 10-hour weekly course workload. The journal must follow the structure below:
AI Lab Journal Report
AI Lab Journal: TensorFlow Playground Classification Report
1. Lab Setup & Key Definitions
- What is an "Epoch"? Explain in 1–2 sentences in your own words based on what you observed.
- What is a "Feature" in this playground? Explain what X1 and X2 represent.
2. Architecture & Performance Table
| Dataset | Hidden Layers | Neurons per Layer | Advanced Features Used? | Did it successfully classify? (Yes/No) |
|---|---|---|---|---|
| 1. Blobs | 0 | 0 | None (X1, X2 only) | |
| 2. Circle | 1 | 3 | None (X1, X2 only) | |
| 3. Spiral | [Your Data] | [Your Data] | [e.g., Yes, added X12] |
3. Test Results & Screenshot Evidence
- Experiment 2 (Circle) Observation: Describe how the shape of the background colors changed when you added 3 neurons.
[Insert a screenshot of your successful Circle model here]
- Experiment 3 (Spiral) Observation: Describe your struggle with the spiral. What specific combination of layers and features finally worked best?
[Insert a screenshot of your best Spiral model here]
4. Core Reflections
- Question 1: In Experiment 2 (The Circle), why did the network fail completely when it had 0 Hidden Layers? What does this tell you about the limitations of "Linear" algorithms?
- Question 2: Look at the lines connecting the neurons in the UI. You will notice they have different thicknesses and colors (blue and orange). Based on the lecture, what do these connecting lines represent in a Neural Network, and why do they change thickness as the training progresses?
🎯 Pro-Tips for Students (How to Avoid Common Pitfalls)
- Don't Overcomplicate Too Early: For simple data (like the blobs), adding 5 layers with 8 neurons each won't improve it; it will actually make the boundary jagged and overly complex (a phenomenon called Overfitting). Rule of thumb: Always start simple and only add layers if the AI fails.
- Watch the Epochs: Sometimes the AI gets "stuck" for a few seconds, and then suddenly figures it out around Epoch 300. Give it a little time to learn before you hit the stop button!