Linear Regression Calculator
Fit a least-squares regression line to a set of (x, y) data points. Get the slope, intercept, R² value, and a chart of the fitted line.
6 valid points detected
y = 1.9971x + 0.0267
Recommended Settings
Pro Tips
- •R² ranges from 0 to 1 and indicates how well the line fits the data - closer to 1 means a stronger linear relationship
- •The slope tells you how much y changes for each one-unit increase in x, and the intercept is the predicted y value when x is 0
- •Predictions far outside your original data's x range are extrapolations and become less reliable the further you go
- •This calculates simple linear regression with one predictor variable - it won't fit curves or multiple variables
Most Popular
Most users paste x,y data copied from a spreadsheet to quickly find the trend line
When to Use This Tool
Find the linear trend in a data set, such as sales over time or a relationship between two measurements.
Calculate the least-squares regression line and R² value for a statistics course.
Use a fitted linear trend to make a rough prediction for a new x value.
Use the R² value to gauge how strong the linear relationship is between two variables.
How It Works
Parse each line of input into an (x, y) coordinate pair
Calculate the slope and intercept that minimize the sum of squared vertical distances between the data points and the line (the least-squares method)
Calculate R² by comparing how much of the variation in y is explained by the line versus the total variation in y
Plot the data points and the fitted line together on a chart
100% Private
Files never leave your device. All processing happens locally in your browser.
Lightning Fast
Powered by Least-squares linear regression for optimal performance on modern browsers.
Open Source
Built with verified, open-source libraries. Fully transparent.
Frequently Asked Questions
What is R² and how do I interpret it?
R² (the coefficient of determination) ranges from 0 to 1 and measures how well the line fits your data. An R² of 1 means the line fits perfectly, while a value close to 0 means the linear relationship explains very little of the variation in y.
How is the regression line calculated?
This tool uses the least-squares method, which finds the slope and intercept that minimize the sum of the squared vertical distances between each data point and the line.
Can I use this to predict values outside my data range?
You can enter any x value for a prediction, but predictions far outside the range of your original data (extrapolation) are less reliable, since the linear trend may not continue to hold.
Is my data sent to a server?
No. All calculations happen instantly in your browser using JavaScript. Nothing you enter is transmitted anywhere.
What if my data isn't actually linear?
This tool always fits a straight line, even to non-linear data - it will just result in a low R² value, which is a signal that a linear model isn't a good fit for your data.