
The simplest machine-learning model is a straight line through your data. Excel can fit it with plain formulas β no Analysis ToolPak needed.
Example: ad spend vs sales
Put monthly ad spend in B2:B25 (x) and sales in C2:C25 (y).
“`excel
=SLOPE(C2:C25, B2:B25) ‘ extra sales for each extra βΉ1 of ads
=INTERCEPT(C2:C25, B2:B25) ‘ predicted sales with zero ad spend
=RSQ(C2:C25, B2:B25) ‘ 0-1: how much of the variation the line explains
=FORECAST.LINEAR(50000, C2:C25, B2:B25) ‘ predicted sales at βΉ50,000 spend
“`
LINEST: everything at once
“`excel
=LINEST(C2:C25, B2:B25, TRUE, TRUE)
“`
In Excel 365 this spills a 5Γ2 block of statistics: slope and intercept in the first row, their standard errors in the second, RΒ² in the third, then the F statistic and sums of squares. For several inputs (ad spend and discount %), pass a multi-column x range: =LINEST(D2:D25, B2:C25, TRUE, TRUE). Note that LINEST returns the coefficients in reverse column order.
Reading the result sensibly
- RΒ² of 0.8 means the line explains 80% of the ups and downs β it does not prove ads cause sales.
- Predict only inside the range you have data for. A line fitted on βΉ10kββΉ60k spends says nothing reliable about βΉ5 lakh.
- Always chart it: Insert β Scatter, then Add Trendline β Display equation and RΒ². One outlier can drag the whole line.
TREND returns fitted values for a whole column at once β =TREND(C2:C25, B2:B25) β handy for a “predicted vs actual” chart.
Want to see how the computer actually finds that line? Read linear regression from scratch in Python.