Practical 1: Building Your First "Toy" Brain
Imagine you are a baker. You have Flour (X) and you want to reach a specific Sweetness (Y) .
- The Goal: Find the perfect "Cake Recipe."
- The Secret Recipe: Sweetness = (Multiplier x Flour) + Baseline
- The Mission: The computer starts with random numbers for the Multiplier (W) and Baseline (B) . It must learn the correct ones by "tasting" the cake and fixing the recipe.
Task 1—The "Manual" Baker (NumPy Code) (Download)
In this step, you do all the work.
- You calculate the sweetness by hand.
- You use a math formula to find out who to "blame" (the Flour or the Sugar) when the cake tastes bad.
- Why? To see how the math actually works before we let the computer take over.
Task 2—The "Automatic" Factory (PyTorch Code) (Download)
In this step, we use PyTorch (our high-tech factory).
- We use a tool called
loss.backward(). - This tool automatically calculates the "blame" and fixes the recipe for us.
- Why? To see how much faster and easier it is to let PyTorch handle the math.
Questions to Think About
- If the cake is too sweet, should we decrease the Multiplier or the Baseline?
- How does the computer know it has finally found the "Perfect Recipe"?