This module introduces linear regression, one of the fundamental algorithms in machine learning. Students will learn how to model relationships between variables, understand the mathematics behind ordinary least squares, and implement regression models from scratch and using scikit-learn.
By the end of this module, students will be able to:
Linear regression mirrors the ancient principle of “finding the middle way” (中庸之道). Just as traditional wisdom seeks balance and optimal paths, linear regression finds the best-fitting line that minimizes overall error, achieving mathematical harmony in data relationships.
README.md - This filetheory.html - Interactive theory explanationvisualization.html - Visual demonstrationscode/ - Implementation notebooks
01_from_scratch.ipynb - Build linear regression from scratch02_sklearn_implementation.ipynb - Using scikit-learn03_advanced_techniques.ipynb - Regularization and feature engineeringcase_study/ - Practical application
boston_housing.ipynb - Complete case studydata/ - Dataset filesexercises/ - Practice problemssolutions/ - Exercise solutions# Simple linear regression example
from sklearn.linear_model import LinearRegression
import numpy as np
# Generate sample data
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([2, 4, 6, 8, 10])
# Train model
model = LinearRegression()
model.fit(X, y)
# Make predictions
predictions = model.predict([[6]])
print(f"Prediction for x=6: {predictions[0]}")