Linear Regression Calculator
Least squares · R² · residual plot · prediction
Result
Enter data and click Calculate
Compute the regression equation, R², correlation, and make predictions.
Scatter Plot & Regression Line
Python Compiler
What Is Linear Regression?
Linear regression models the relationship between a dependent variable (Y) and independent variable (X) by fitting the best straight line through the data using the least squares method.
Slope (b)
How much Y changes for each 1-unit increase in X. Positive = upward trend, negative = downward.
Intercept (a)
The predicted value of Y when X = 0. The starting point of the regression line.
R² (Fit Quality)
Proportion of variance in Y explained by X. Ranges from 0 (no fit) to 1 (perfect fit).
Key Formulas
Understanding R²
| R² Range | Interpretation | Fit Quality |
|---|---|---|
| 0.90 – 1.00 | 90–100% of variance explained | Excellent |
| 0.70 – 0.89 | 70–89% of variance explained | Good |
| 0.50 – 0.69 | 50–69% of variance explained | Moderate |
| 0.00 – 0.49 | Less than 50% explained | Weak |
Tip: A high R² does not guarantee a good model. Always visualize residuals to check for patterns that indicate model violations (non-linearity, heteroscedasticity).
Assumptions of Linear Regression
Linearity
The relationship between X and Y is approximately linear. Check with a scatter plot.
Independence
Observations are independent of each other. No autocorrelation in residuals.
Homoscedasticity
Residuals have constant variance across all X values. Fan-shaped patterns indicate violation.
Normality
Residuals are approximately normally distributed. Less critical for large samples.