How to use the Linear Regression Calculator
- 1. Enter X and YPaste your independent and dependent values in the same order.
- 2. Add a predictionOptionally type an X value to predict its Y.
- 3. Read the fitSee the equation, R², slope p-value, residuals and chart.
Least squares formulas
Simple linear regression finds the line that minimises the sum of squared errors. The slope is b₁ = Σ(x − x̄)(y − ȳ) ÷ Σ(x − x̄)² and the intercept is b₀ = ȳ − b₁ × x̄. R² = 1 − SSE ÷ SST tells you the share of variation in Y explained by X.
Worked example: for X = 1, 2, 3, 4, 5 and Y = 2, 4, 5, 4, 5, Σ(x − x̄)(y − ȳ) = 6 and Σ(x − x̄)² = 10, so b₁ = 0.6 and b₀ = 4 − 0.6 × 3 = 2.2. The line is y = 0.6x + 2.2, R² = 0.6, and the prediction for X = 6 is 5.8.
Checking whether the line is any good
- Residuals (actual − predicted) should look random. A curve in the residuals means a straight line is the wrong model.
- R² near 1 is a tight fit, but a high R² does not prove cause and can come from one extreme point.
- The slope p-value tests whether the slope differs from zero. With few points, uncertainty is large.
- Extrapolation beyond your X range is risky; the relationship may change.
This is the same model as Excel's SLOPE, INTERCEPT and RSQ functions, and scikit-learn's LinearRegression with one feature. For several predictors you need multiple regression, which this page does not do. Watch a model learn the same line step by step in the gradient descent visualizer, or check strength first with the correlation calculator.
Frequently asked questions
Is this the same as Excel's trendline?
Yes. A linear trendline in Excel uses ordinary least squares, so the equation and R² match.
Can it fit a curve?
No. It fits a straight line only. For curves you would transform the data or use polynomial regression.
Is the Linear Regression Calculator free?
Yes, the Linear Regression Calculator is free. The first time you see your first result, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.