Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand the fundamental paradigm shift from rule-based deterministic programming to data-driven probabilistic learning.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Model parameters (weights) | The learnable dials inside the AI model | |
| Loss function | A penalty metric for incorrect predictions | |
| Input and true label | The training data examples |
Adjusting linear model parameters (slope m and intercept b) to minimize squared error across data points.
Result: Low loss signifies the learned rule closely mirrors reality
Human analyst specifies: Input Data + Handcrafted Rules -> Output Answers.
Optimization algorithm ingests: Input Data + Ground Truth Answers -> Learned Rules (Model).
The learned model is deployed to evaluate new, previously unseen inputs.
Problem: Rule-based spam filters searching for "VIAGRA" were easily bypassed by spammers typing "V1@GR@".
Solution: Bayesian and transformer-based spam filters learn statistical semantic distributions and catch adversarial variants automatically.
Problem: Calculating overtime wages and tax deductions requires 100% legal compliance and zero probabilistic uncertainty.
Solution: Deterministic if-else business logic is strictly preferred over machine learning for accounting and tax computation.
Interactive activity component
See the contrast between a hardcoded rule and a scikit-learn linear regression model learning from data.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install scikit-learn numpy1 import numpy as np 2 from sklearn.linear_model import LinearRegression
import numpy as np → Array manipulation
from sklearn.linear_model import LinearRegression → Import classical linear regression learner
1 # Problem: Convert Celsius to Fahrenheit 2 # Traditional Rule-Based Program: 3 def traditional_c2f(c): 4 return c * 1.8 + 32.0 5 6 # Machine Learning Program (Learning the rule from data alone): 7 X_celsius = np.array([[-40], [0], [20], [37], [100]]) 8 y_fahr = np.array([-40.0, 32.0, 68.0, 98.6, 212.0]) 9 model = LinearRegression() 10 model.fit(X_celsius, y_fahr) 11 12 test_c = 25.0 13 rule_result = traditional_c2f(test_c) 14 ml_result = model.predict([[test_c]])[0] 15 print(f"Traditional Rule: {rule_result:.1f}°F") 16 print(f"Learned ML Model: {ml_result:.1f}°F (Learned slope={model.coef_[0]:.2f}, bias={model.intercept_:.2f})")
# Problem: Convert Celsius to Fahrenheit
Formula: F = C * 1.8 + 32
# Traditional Rule-Based Program:
Hand-coded formula
def traditional_c2f(c):
Deterministic function
return c * 1.8 + 32.0
Exact mathematical rule
# Machine Learning Program (Learning the rule from data alone):
Data driven
X_celsius = np.array([[-40], [0], [20], [37], [100]])
Input features
y_fahr = np.array([-40.0, 32.0, 68.0, 98.6, 212.0])
Target labels
model = LinearRegression()
Instantiate learner
model.fit(X_celsius, y_fahr)
Learn the relationship!
test_c = 25.0
Test on room temperature 25C
rule_result = traditional_c2f(test_c)
Rule result
ml_result = model.predict([[test_c]])[0]
Model prediction
print(f"Traditional Rule: {rule_result:.1f}°F")
Display rule output
print(f"Learned ML Model: {ml_result:.1f}°F (Learned slope={model.coef_[0]:.2f}, bias={model.intercept_:.2f})")
Display ML output
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Comparing Rule-Based vs Machine Learning Prediction 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install scikit-learn numpy 8 9 # Step 2: Import libraries 10 import numpy as np 11 from sklearn.linear_model import LinearRegression 12 13 # Step 3: Run Demonstration 14 # Problem: Convert Celsius to Fahrenheit 15 # Traditional Rule-Based Program: 16 def traditional_c2f(c): 17 return c * 1.8 + 32.0 18 19 # Machine Learning Program (Learning the rule from data alone): 20 X_celsius = np.array([[-40], [0], [20], [37], [100]]) 21 y_fahr = np.array([-40.0, 32.0, 68.0, 98.6, 212.0]) 22 model = LinearRegression() 23 model.fit(X_celsius, y_fahr) 24 25 test_c = 25.0 26 rule_result = traditional_c2f(test_c) 27 ml_result = model.predict([[test_c]])[0] 28 print(f"Traditional Rule: {rule_result:.1f}°F") 29 print(f"Learned ML Model: {ml_result:.1f}°F (Learned slope={model.coef_[0]:.2f}, bias={model.intercept_:.2f})")
Traditional program computes using hardcoded arithmetic.
ML program discovers slope 1.8 and intercept 32.0 through matrix inversion.
Both yield 77.0°F, but the ML model learned the rule purely from five examples.
Input temperature 25.0°C
Traditional Rule: 77.0°F Learned ML Model: 77.0°F (Learned slope=1.80, bias=32.00)
The linear regression model discovered the exact physical laws of thermal expansion solely from five observation pairs without any human explaining thermodynamics.
From classical prediction to a one-qubit quantum circuit.
Test your understanding with these questions. Remember, this is for learning, not examination!