Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Master the most commercially dominant form of AI: mapping inputs to targets via classification and regression.
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| True value | Actual recorded outcome | |
| Predicted value | Model prediction | |
| Number of samples | Sample size |
Errors for two predictions: true [10, 20], predicted [12, 19].
Result:
Assemble tabular matrix X (N samples, D features) and target vector y.
Define MSE for regression or Cross-Entropy for classification.
Backpropagation or convex solver minimizes error over parameter space.
Problem: Banks need to classify applicants as Low Risk vs High Risk.
Solution: Logistic regression or XGBoost predicts probability of repayment.
Problem: Predicting peak temperature tomorrow in degrees Celsius.
Solution: Regression model trained on atmospheric pressure and satellite metrics.
Interactive activity component
Train a classifier and a regressor in under 15 lines of code.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install scikit-learn1 from sklearn.linear_model import LinearRegression, LogisticRegression 2 import numpy as np
from sklearn.linear_model import LinearRegression, LogisticRegression → Import both models
import numpy as np → NumPy arrays
1 # Hours studied vs Exam Score (0-100) -> REGRESSION 2 X_study = np.array([[1], [2], [4], [6], [8]]) 3 y_score = np.array([35, 50, 70, 85, 95]) 4 reg = LinearRegression().fit(X_study, y_score) 5 print(f"Predicted Score for 5 hours: {reg.predict([[5]])[0]:.1f}") 6 7 # Hours studied vs Pass/Fail (0=Fail, 1=Pass) -> CLASSIFICATION 8 y_pass = np.array([0, 0, 1, 1, 1]) 9 clf = LogisticRegression().fit(X_study, y_pass) 10 print(f"Pass/Fail Prediction for 3 hours: {clf.predict([[3]])[0]} (Probability: {clf.predict_proba([[3]])[0][1]:.2f})")
# Hours studied vs Exam Score (0-100) -> REGRESSION
Regression data
X_study = np.array([[1], [2], [4], [6], [8]])
Hours
y_score = np.array([35, 50, 70, 85, 95])
Continuous scores
reg = LinearRegression().fit(X_study, y_score)
Fit regressor
print(f"Predicted Score for 5 hours: {reg.predict([[5]])[0]:.1f}")
Regression output
# Hours studied vs Pass/Fail (0=Fail, 1=Pass) -> CLASSIFICATION
Classification data
y_pass = np.array([0, 0, 1, 1, 1])
Discrete classes
clf = LogisticRegression().fit(X_study, y_pass)
Fit classifier
print(f"Pass/Fail Prediction for 3 hours: {clf.predict([[3]])[0]} (Probability: {clf.predict_proba([[3]])[0][1]:.2f})")
Classification output
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Classification vs Regression in Scikit-Learn 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install scikit-learn 8 9 # Step 2: Import libraries 10 from sklearn.linear_model import LinearRegression, LogisticRegression 11 import numpy as np 12 13 # Step 3: Run Demonstration 14 # Hours studied vs Exam Score (0-100) -> REGRESSION 15 X_study = np.array([[1], [2], [4], [6], [8]]) 16 y_score = np.array([35, 50, 70, 85, 95]) 17 reg = LinearRegression().fit(X_study, y_score) 18 print(f"Predicted Score for 5 hours: {reg.predict([[5]])[0]:.1f}") 19 20 # Hours studied vs Pass/Fail (0=Fail, 1=Pass) -> CLASSIFICATION 21 y_pass = np.array([0, 0, 1, 1, 1]) 22 clf = LogisticRegression().fit(X_study, y_pass) 23 print(f"Pass/Fail Prediction for 3 hours: {clf.predict([[3]])[0]} (Probability: {clf.predict_proba([[3]])[0][1]:.2f})")
Fits best straight line predicting exact score.
Fits sigmoid curve calculating probability of passing.
Study hours: 5 for score, 3 for pass/fail
Predicted Score for 5 hours: 77.0 Pass/Fail Prediction for 3 hours: 1 (Probability: 0.73)
Regression outputs an unbounded continuous score (77.0), while classification outputs a discrete class outcome (1 = Pass) with confidence 73%.
Data, prediction, and the bridge to modern artificial intelligence.
Test your understanding with these questions. Remember, this is for learning, not examination!