Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Delve into the core mechanics of machine learning: how statistical algorithms turn raw data into actionable predictive knowledge.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Optimal parameters | The best weights for our model | |
| Loss function | Penalty for error | |
| Number of training samples | Size of dataset |
Finding optimal line slope m for points (1, 2) and (2, 4).
Result: Optimal parameter is m* = 2.0 (zero loss)
Define target label, evaluation metric, and input features.
Handle missing values, encode text/categories, and normalize scales.
Train candidate algorithms on training split.
Evaluate on independent test set and deploy via microservice API.
Problem: Assessing default probability for mortgage applicants.
Solution: Logistic regression and gradient boosting evaluate income, debt, and credit history.
Problem: Factory machines breaking down unexpectedly causing factory downtime.
Solution: Vibration and temperature sensors feed ML models that flag wear-and-tear days before failure.
Interactive activity component
Implement gradient descent to learn a relationship without any ML libraries.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install numpy1 import numpy as np
import numpy as np β NumPy for vector operations
1 # Ground truth rule: y = 3 * x + 2 2 X = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) 3 y = np.array([5.0, 8.0, 11.0, 14.0, 17.0]) 4 5 w = 0.0 # Initialize weight 6 b = 0.0 # Initialize bias 7 lr = 0.01 # Learning rate 8 9 for epoch in range(1000): 10 y_pred = w * X + b 11 error = y_pred - y 12 dw = (2/len(X)) * np.sum(error * X) # Gradient w.r.t w 13 db = (2/len(X)) * np.sum(error) # Gradient w.r.t b 14 w -= lr * dw # Update weight 15 b -= lr * db # Update bias 16 17 print(f"Learned equation: y = {w:.2f} * x + {b:.2f}") 18 print(f"Prediction for x=10: {w * 10 + b:.2f} (True answer: 32.0)")
# Ground truth rule: y = 3 * x + 2
Target rule
X = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
Inputs
y = np.array([5.0, 8.0, 11.0, 14.0, 17.0])
Targets
w = 0.0 # Initialize weight
Initial weight
b = 0.0 # Initialize bias
Initial bias
lr = 0.01 # Learning rate
Step size
for epoch in range(1000):
Run 1000 training iterations
y_pred = w * X + b
Model forward pass
error = y_pred - y
Calculate error
dw = (2/len(X)) * np.sum(error * X) # Gradient w.r.t w
Compute gradient dw
db = (2/len(X)) * np.sum(error) # Gradient w.r.t b
Compute gradient db
w -= lr * dw # Update weight
Step down gradient
b -= lr * db # Update bias
Step down gradient
print(f"Learned equation: y = {w:.2f} * x + {b:.2f}")
Output learned parameters
print(f"Prediction for x=10: {w * 10 + b:.2f} (True answer: 32.0)")
Test extrapolation
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # A Minimal Machine Learning Loop from Scratch 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install numpy 8 9 # Step 2: Import libraries 10 import numpy as np 11 12 # Step 3: Run Demonstration 13 # Ground truth rule: y = 3 * x + 2 14 X = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) 15 y = np.array([5.0, 8.0, 11.0, 14.0, 17.0]) 16 17 w = 0.0 # Initialize weight 18 b = 0.0 # Initialize bias 19 lr = 0.01 # Learning rate 20 21 for epoch in range(1000): 22 y_pred = w * X + b 23 error = y_pred - y 24 dw = (2/len(X)) * np.sum(error * X) # Gradient w.r.t w 25 db = (2/len(X)) * np.sum(error) # Gradient w.r.t b 26 w -= lr * dw # Update weight 27 b -= lr * db # Update bias 28 29 print(f"Learned equation: y = {w:.2f} * x + {b:.2f}") 30 print(f"Prediction for x=10: {w * 10 + b:.2f} (True answer: 32.0)")
Computes current predictions using initial parameters (w=0, b=0).
Calculates partial derivatives showing which direction reduces error.
Updates w and b; within 1000 iterations converges to w=3.00, b=2.00.
Points following y = 3x + 2
Learned equation: y = 3.00 * x + 2.00 Prediction for x=10: 32.00 (True answer: 32.0)
Through pure gradient feedback, the computer discovered the exact linear coefficients without human intervention.
NumPy arrays, pandas DataFrames, train-test splits, and scikit-learn models.
Test your understanding with these questions. Remember, this is for learning, not examination!