Regression predicts a number based on other numbers. How much will we spend next month? What price should this house have? How much revenue does this ad campaign drive?
In finance, regression is everywhere: estimating costs, forecasting revenue, valuing assets, and understanding what drives expenses. It's the workhorse of predictive analytics.
The simplest regression draws a straight line through your data. Given one input x, it predicts one output y:
m is the slope (how much y changes per unit of x). b is the intercept (where the line crosses zero). Fitting the model finds the best m and b so the line is as close as possible to all data points.
Example: predict monthly sales from advertising spend. If m = 3, each $1 in ads returns $3 in sales on average.
Real financial decisions depend on many factors. Multiple regression handles this by combining inputs:
Example: predict monthly sales from advertising, price, season, and competitor activity β all at once. Each coefficient measures that factor's contribution, holding the others constant.
Interpretation matters: a coefficient of 2 for price means "a $1 price increase raises sales by $2, when everything else is held fixed." That's a powerful insight.
Linear regression makes assumptions. If they're badly violated, coefficients and predictions can be misleading. The main ones:
| Assumption | What It Means | How to Check |
|---|---|---|
| Linearity | Relationship is roughly a straight line | Scatter plots, residual plots |
| Independence | Observations don't influence each other | Check for repeated measures |
| Homoscedasticity | Spread of residuals stays consistent | Plot residuals vs. fitted |
| No strong multicollinearity | Inputs aren't too correlated with each other | Correlation matrix, VIF |
When you have many features, regression can overfit β it memorizes noise. Regularization adds a penalty to the model for using large coefficients.
Ridge (L2) shrinks coefficients toward zero, reducing overfitting. Lasso (L1) can push some coefficients all the way to zero β effectively performing feature selection. Very handy in finance, where most features contribute only a little.
Not every relationship is a straight line. Sometimes sales grow slowly, then fast, then slow again β a curve. Polynomial features (like xΒ², xΒ³) let regression fit curves.
Interaction features (xβ Γ xβ) capture "when both happen together." Example: "price Γ advertising" captures how price effects depend on ads.
But watch out: more features means more complexity and more risk of overfitting. Use regularization alongside.
How do you know if your regression is "good"? Three key metrics:
| Metric | What It Measures | When It Helps |
|---|---|---|
| RMSE | Avg error, punishing big misses more | When big errors are very costly |
| MAE | Avg absolute error | When every error is equally bad |
| RΒ² | % of variance explained by the model | Comparing models on the same data |
RMSE β MAE means errors are balanced. RMSE β« MAE means a few big errors dominate β worth investigating.
Draw the line: Take 5 data points (hours studied vs. test scores). Draw a rough bestβfit line by hand. Then use Python's LinearRegression to compute the actual slope and intercept. Compare your guess to the real answer.
Interpret a coefficient: A regression of "monthly sales" on "advertising spend" gives a coefficient of 2.5. Explain in one sentence what this means for the business.
Multiple inputs: Build a small regression that predicts "monthly revenue" from "advertising" and "number of staff." Compare the coefficient sizes β which factor matters more in your toy dataset?
Regularization test: Fit a regression on many features (say, 10 dummy features). Compare the coefficients with and without ridge regularization. Notice which shrink and which stay stable.
RMSE vs. MAE: Compute both metrics for two different models on the same test data. Which model has better MAE? Which has better RMSE? Which would you pick for financial forecasting β and why?
Interaction insight: Add an interaction feature (e.g., "price Γ discount") to a simple regression. Does it improve the model? Write one sentence explaining why interaction features can matter in business.
By the end of this module, you'll be able to: fit simple and multiple regression models, check assumptions, interpret coefficients in financial terms, apply ridge/lasso regularization, engineer polynomial and interaction features, and evaluate regressions with RMSE, MAE, and RΒ².