Linear Regression

Find the best-fitting line through data

Linear regression finds the line that best fits a set of data points by minimizing the sum of squared residuals. This simulation lets you generate data with various noise levels and watch how the algorithm finds the optimal line.

💡 Tip: Click anywhere on the chart to add custom data points!
y = mx + b

R² Score

-

Fitted Slope

-

Fitted Intercept

-

Mean Squared Error

-

How Linear Regression Works

Linear regression finds the line y = mx + b that minimizes the sum of squared errors between predicted and actual values. The optimal parameters are found using the least squares method:

m = Σ((x - x̄)(y - ȳ)) / Σ((x - x̄)²)
b = ȳ - m·x̄

Where x̄ and ȳ are the means of x and y values. The R² score measures how well the line fits the data, with 1.0 being a perfect fit.

Key concepts:

  • Residuals: The vertical distances between data points and the fitted line
  • Least Squares: Minimizing the sum of squared residuals
  • R² Score: Proportion of variance explained by the model