Day 25 of 30Artificial Intelligence
📈Regression — Predicting Numbers
🎯 Today's objective
Predict continuous values with linear regression.
📖 Key concepts
- Regression predicts a number (not a class)
- LinearRegression fits a best-fit line
- Evaluate with R² / error
- Relationship ≠ causation
💻 Try this code
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1],[2],[3],[4],[5]])
y = np.array([2, 4, 6, 8, 10])
m = LinearRegression().fit(X, y)
print("predict 6 ->", m.predict([[6]])) # ~12👥 Learn it your way
🧒 Young Explorers
Classification picks a label; regression guesses a number (like a price or score).
Your task
Fit the line above and predict the value for 10. Does it match the pattern?
💼 Professionals
Inspect coef_/intercept_; evaluate with R²/MAE; beware extrapolation beyond training range.
Your task
Fit hours-studied → exam-score on toy data; report the slope and an R² score.
🤖 AI connection
Predicting prices, demand, energy use, risk — regression is the workhorse of business AI. Same fit/predict API you already know.
✅ Quick check
Classification vs regression?
Classification predicts a category; regression predicts a number.
Does correlation prove causation?
No.