|
|
||
|
This interactive tutorial demonstrates Least Squares Regression, a fundamental statistical method for finding the line of best fit through a set of data points. The key insight is that the regression line minimizes the sum of the squared residuals - visually represented as the total area of the red/blue squares in the visualization. Click anywhere on the canvas to add data points, then watch as the regression line automatically adjusts to minimize the total squared error. Drag existing points to see how the line responds in real-time. The semi-transparent squares attached to each point visually represent the "squared" in "Least Squares" - their total area is exactly what the algorithm minimizes. Interactive ControlsClick: Add a new data point at the clicked location. Drag: Move existing points to see how the regression line adapts. Double-Click: Remove a point from the dataset. Clear All: Remove all points and reset the visualization. Preset Dropdown: Choose from 10 preset datasets with various correlation coefficients (r ≈ 0 to ±0.95), slopes (horizontal, steep), and special cases (with outlier). Auto Fit: Snap the line back to the optimal least squares fit after manual adjustment. Show Squares: Toggle visibility of the squared residual areas. Red squares indicate points above the line, blue squares indicate points below. Show Residuals: Toggle visibility of the vertical residual lines (yellow) connecting each point to the regression line. Show Grid: Toggle the background coordinate grid. Confidence Band: Toggle the 95% confidence interval band around the regression line. Animate to Optimal: Watch the line animate from a random starting position to the optimal solution. Orange Knobs: Drag the endpoints of the regression line to try your own fit and compare SSE values. Understanding the VisualizationGreen Points: Your data points (xi, yi). Cyan/Orange Line: The regression line y = mx + b. Cyan when auto-fitted, orange when manually adjusted. Orange Knobs: Draggable endpoints at the line's edges - drag them to experiment with different slopes and intercepts. Yellow Lines: Residuals - the vertical distance from each point to the line: ei = yi - ŷi Red/Blue Squares: The squared residuals ei². Red = point above line, Blue = point below line. Total area = SSE. Light Blue Band: 95% confidence interval (when enabled) - wider at edges where predictions are less certain. Contour Plot (Top-Left): Shows the SSE error surface as a function of slope (m) and intercept (b). Blue = low SSE (good), Red = high SSE (bad). Green Star: The optimal (m, b) position on the contour plot - the minimum of the error surface. Yellow Circle: Your current (m, b) position on the contour plot - drag it to explore the error surface! Error Breakdown Panel: Shows individual squared errors as rectangles and the total SSE as a combined square. Mathematical ModelThe goal of Least Squares Regression is to find the slope (m) and intercept (b) that minimize the Sum of Squared Errors: SSE = Σi=1n (yi - ŷi)² = Σi=1n (yi - mxi - b)² where yi is the actual y-value, ŷi is the predicted y-value from the line, m is the slope, and b is the y-intercept. Slope Formula: m = Σ(xi - x̄)(yi - ȳ) / Σ(xi - x̄)² Intercept Formula: b = ȳ - m·x̄ where x̄ and ȳ are the means of the x and y values respectively. Key Insights:
Controls
Equation:
y = ? (need ≥2 points)
SSE:
0.00
Points:
0
Slope (m):
0.0000
Intercept (b):
0.0000
Correlation (r):
0.0000
R² :
0.00%
Click to add points | Drag to move points | Double-click to remove points | Drag orange knobs to try your own line
Error Squares Breakdown
Understanding the Statistics
Interactive Features Explained
Applications of Least Squares Regression
Understanding the Error SurfaceThe contour plot visualizes a key concept: the error surface (or loss landscape). Every point on this surface represents a specific (slope, intercept) pair and its corresponding SSE. The optimization problem is to find the lowest point on this surface.
Extending to Multiple RegressionThis visualization shows Simple Linear Regression with one predictor variable (x). The same principle extends to Multiple Linear Regression: y = b₀ + b₁x₁ + b₂x₂ + ... + bnxn In higher dimensions, instead of minimizing the distance to a line, we minimize the distance to a hyperplane. The math becomes matrix algebra, but the core principle remains: minimize the sum of squared residuals.
|
||