Variable Relationships › Simple Linear Regression: Modeling Relationships
Machine Learning from ScratchAll chapters Variable Relationships › Simple Linear Regression: Modeling RelationshipsOne section · Sections in this chapter5 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
While correlation measures the strength of a linear relationship, regression goes further by modeling the relationship explicitly. Simple linear regression fits a line through the data to predict a dependent variable from an independent variable . This line represents the best linear approximation of how changes as changes.
The simple linear regression model is:
Where:
- : Dependent variable (response)
- : Independent variable (predictor)
- : Intercept (value of when )
- : Slope (change in for unit change in )
- : Error term (unexplained variation)
The regression coefficients are typically estimated using ordinary least squares (OLS), which minimizes the sum of squared residuals. The OLS estimates are:
Notice that the slope coefficient is directly related to the correlation coefficient , scaled by the ratio of standard deviations. This connection reveals that regression and correlation are closely related: correlation measures association strength, while regression quantifies the specific form of that association.
The regression line gives several useful capabilities. First, it allows prediction: given a new value of , we can predict the expected value of using . Second, the slope coefficient quantifies the average change in associated with a one-unit change in . Third, the regression framework allows for statistical inference: we can test whether the relationship is statistically significant and construct confidence intervals for the coefficients.
The following example demonstrates a simple linear regression fit to data with a clear linear relationship. The regression line captures the average tendency of Y to increase with X, while the residuals represent the unexplained variation around this trend.

Understanding what regression optimizes helps build intuition for how the method works. The "least squares" criterion means we're finding the line that minimizes the sum of squared vertical distances from points to the line. These vertical distances are called residuals, and they represent the prediction errors. The following visualization shows these residuals explicitly and illustrates what the regression line accomplishes.
