Simple linear regression fits the straight line ŷ = a + bx that best predicts a numeric outcome from one predictor. The slope b is the average change in y per one-unit increase in x; the intercept a is the predicted y when x = 0. R² is the share of variance in y the line explains, from 0 to 1. Regression predicts and quantifies a relationship, where correlation only measures its strength. Results are validated against SciPy to full precision.

When to use regression

Use simple linear regression when you want to predict or model a numeric outcome from one numeric predictor, and to put a number on the relationship (the slope). If you only need the strength and direction of association, correlation is enough. With several predictors you need multiple regression.

Reading the output

The slope answers “how much does y change per unit of x?” and carries units; the intercept is the baseline; R² near 1 means the line fits closely, near 0 means it barely helps. The p-value on the slope tests whether the true slope differs from zero.

Assumptions (LINE)

Inspect a residual plot to check all four at once — it should look like random scatter.

Common mistakes

Worked example

Advertising spend 1,2,3,4,5 against sales 2,4,5,4,6 fits roughly ŷ = 2.2 + 0.7x with R² ≈ 0.61 — each extra unit of spend adds about 0.7 in sales, explaining 61% of the variation. Enter paired columns above for the full fit and residuals. See the methodology page for details.

Guide: Linear Regression

Linear regression finds the best-fitting straight line through a set of data points. The line is described by the equation: y = slope × x + intercept.

Unlike correlation (which only measures the relationship), regression produces a predictive model: you can plug in a value of x to predict the expected value of y.

Slope: For every 1-unit increase in x, y changes by [slope] units. A slope of 2.5 means y increases by 2.5 for each unit increase in x.

Intercept: The predicted value of y when x = 0. This is only meaningful if x = 0 is a plausible value in your data (e.g. not if x is "age in years" and 0 is outside the measured range).

R² (coefficient of determination) measures how well the regression line fits the data — what proportion of the total variability in y is explained by x. Ranges from 0 to 1.

R² = 0.80 means your regression line accounts for 80% of the variance in y. The remaining 20% is explained by other factors not in your model.

A high R² doesn't guarantee a useful model — always inspect the residual plot and check for patterns.

  • Linearity: The relationship between x and y is linear
  • Independence: Observations are independent
  • Homoscedasticity: The variance of residuals is constant across all x values
  • Normality of residuals: Residuals should be approximately normally distributed
  • No multicollinearity (for multiple regression): Predictor variables should not be highly correlated with each other

Check these with residual plots and normality tests. Violations may require data transformations or different models.

Correlation measures the strength of the relationship between two variables — it is symmetric (r between x and y equals r between y and x).

Regression is asymmetric — you have a predictor (x) and an outcome (y). It quantifies the relationship and produces a predictive equation. Use regression when you want to predict y from x; use correlation when you just want to quantify the association.