📈 Linear Regression Interactive

Click on the chart to add data points, then fit a regression line to see machine learning in action!

Slope (m)

0.00

Intercept (b)

0.00

R² Score

0.00

MSE

0.00

What is Linear Regression?

Linear Regression is one of the most fundamental algorithms in machine learning and statistics. It models the relationship between a dependent variable (y) and one or more independent variables (x) by fitting a linear equation to observed data.

y = mx + b

where:
• m = slope of the line
• b = y-intercept
• x = input variable
• y = predicted output

How It Works

1. Data Collection Click on the chart above to add data points, or generate random data with the button.
2. Model Training The algorithm finds the best-fit line that minimizes the distance between the line and all data points.
3. Optimization Uses Gradient Descent to iteratively adjust the slope (m) and intercept (b) to minimize error.
4. Evaluation R² Score measures how well the model fits the data (1.0 = perfect fit).

Key Metrics

R² (R-squared): Proportion of variance in the dependent variable that's predictable from the independent variable. Ranges from 0 to 1, where 1 indicates perfect fit.

MSE (Mean Squared Error): Average squared difference between predicted and actual values. Lower is better.

Real-World Applications

• Sales Forecasting: Predict future sales based on historical data
• Price Prediction: Estimate house prices, stock prices, etc.
• Risk Assessment: Evaluate insurance premiums or credit risk
• Trend Analysis: Identify patterns in time series data
• Scientific Research: Model relationships between variables