Regression Algorithms Overview
Regression is a supervised learning technique used to predict continuous numerical values based on historical data.
Regression in Simple Words
Use regression when the answer you want is a number that can take many possible values. The model studies past examples and learns how the input features are related to that number.
| House Size | Known Price |
|---|---|
| 1000 sq ft | ₹30 lakh |
| 1500 sq ft | ₹45 lakh |
| 2000 sq ft | ₹60 lakh |
Tiny prediction example
In this deliberately simple data, every extra 500 sq ft adds ₹15 lakh.
- 1800 sq ft is 300 sq ft larger than 1500 sq ft.
- ₹15 lakh for 500 sq ft means ₹0.03 lakh per sq ft.
- Extra price = 300 × 0.03 = ₹9 lakh.
- Estimated price = ₹45 lakh + ₹9 lakh = ₹54 lakh.
A real regression model learns the relationship from data rather than being given this rule directly.
See the idea: points + a fitted relationship
Each dot is a known house. The line represents a simple learned trend used to estimate prices for new house sizes.
Regression vs Classification
| Question | Regression | Classification |
|---|---|---|
| What does it predict? | A numerical value | A category or class |
| Student example | Predict marks = 78 | Predict Pass / Fail |
| House example | Predict price = ₹54 lakh | Predict Expensive / Affordable |
Regression Learning Flow
A Simple Map of Regression Algorithms
- • Simple Linear Regression
- • Multiple Linear Regression
- • Polynomial Regression
- • Ridge Regression
- • Lasso Regression
- • Elastic Net
- • Decision Tree Regression
- • Random Forest Regression
- • Gradient Boosting
- • XGBoost Regression
- • Support Vector Regression
- • KNN Regression
- • Bayesian Regression
- • Neural Network Regression
This is a learning map, not a strict mathematical taxonomy. Some methods can be described in more than one way depending on how they are implemented.
Types of Regression Problems
| Problem Type | Example Real-World Application |
|---|---|
| Price Prediction | House price prediction based on area |
| Forecasting | Weather and temperature forecasting |
| Risk Estimation | Insurance risk and premium prediction |
| Trend Analysis | Stock market trend prediction |
| Demand Prediction | E-commerce demand and inventory forecasting |
| Scientific Prediction | Biological growth, temperature/pressure estimation |
14 Core Regression Algorithms
1. Simple Linear Regression
What it is: Finds a straight-line relationship between one independent variable and one dependent variable.
"Think of this as the "hello world" of machine learning. It's elegantly simple: you're just trying to draw the best straight line through a cloud of data points. It works beautifully when you have one clear, predictable relationship—like a bigger house usually means a higher price. But let's be honest, the real world is rarely this simple, and it also remains a useful baseline when a roughly linear relationship is plausible."
Mathematical Formula
y = mx + bPractical Calculation Example
Predicting House Price based on Size. Assuming m = 30 and b = 1000. If size x = 2:
- Step 1: y = 30 × 2 + 1000Substitute x = 2 into y = mx + b.
- Step 2: y = 60 + 1000Multiply the slope by x.
- Step 3: y = 1060Add the intercept to get the prediction.
Predicted Output = 1060
Common Applications
Estimating straightforward, continuous trends like expected sales volume based on advertising spend or basic real estate property value estimation.
Advantages:
- Very simple to understand
- Fast training
- Easy interpretation
Disadvantages:
- Cannot capture complex or curved patterns
- Highly sensitive to outliers
2. Multiple Linear Regression
What it is: Uses multiple input variables simultaneously to predict one continuous output.
"Now we're talking. This is the grown-up version of the simple linear model. Instead of a single line, imagine a flat sheet of rigid glass tilting and balancing across multiple dimensions of data. It respects the fact that things like house prices depend on size, location, and age all simultaneously. It is often a useful baseline because the coefficients remain relatively easy to interpret."
Mathematical Formula
y = b₀ + b₁x₁ + b₂x₂ + ... + bₙxₙPractical Calculation Example
Predicting Price using Area and Bedrooms. b₀ = 5K, b₁(Area)=300, b₂(Bedrooms)=10K. Area=1000, Bed=3:
- Step 1: y = 5000 + 300(1000) + 10000(3)Substitute Area = 1000 and Bedrooms = 3.
- Step 2: y = 5000 + 300000 + 30000Calculate the contribution of each feature.
- Step 3: y = 335000Add the intercept and feature contributions.
Predicted Output = 335,000
Common Applications
Predicting crop yields from temperature, rainfall, and fertilizer usage; estimating university admission likelihood based on multiple student scores.
Advantages:
- Better prediction than simple regression
- Interpretable coefficients
Disadvantages:
- Multicollinearity issues
- Assumes linear relationships exist across all features
3. Polynomial Regression
What it is: Models nonlinear relationships by fitting a curved polynomial line to the data.
"What if your data doesn't follow a straight line? What if it swoops, dips, or arcs? Polynomial regression lets our rigid line bend. It can follow curved patterns, but high polynomial degrees can become too flexible and overfit the training data."
Mathematical Formula
y = b₀ + b₁x + b₂x² + b₃x³ + ...Practical Calculation Example
For a curved relationship equation y = 2 + 3x + x². If x = 4:
- Step 1: y = 2 + 3(4) + 4²Substitute x = 4 into the polynomial.
- Step 2: y = 2 + 12 + 16Calculate 3 × 4 and 4².
- Step 3: y = 30Add the three terms.
Predicted Output = 30
Common Applications
Modeling epidemic spread or viral growth, tracking biological tissue growth rates, analyzing material stress and yield point testing parameters.
Advantages:
- Can capture curved polynomial patterns
- Highly flexible
Disadvantages:
- Higher polynomial degrees can overfit
- Harder to interpret mathematically
4. Ridge Regression (L2)
What it is: A regularized version of linear regression that adds a L2 penalty term to shrink coefficients and reduce overfitting.
"As we dump more and more columns of data into our models, they tend to get confused by features that are too similar to each other. Ridge is our steady hand in the chaos. It mathematically "punishes" features for being too loud or too aggressive. By shrinking the mathematical weights naturally, Ridge can make coefficient estimates more stable when predictors are strongly correlated or the unregularized model is too flexible."
Mathematical Formula
Loss = RSS + λ ∑ (w_j)²Practical Calculation Example
If mathematical Error (RSS)=100, Lambda(λ)=0.1, sum of squared weights=50:
- Step 1: Penalty = 0.1 × 50 = 5Multiply λ by the sum of squared weights.
- Step 2: Total Loss = 100 + 5Add the Ridge penalty to the original RSS error.
- Step 3: Total Loss = 105This is the regularized objective for this tiny example.
Total Computed Loss = 105
Common Applications
Genomic data analysis and research where features highly correlate, or complex housing prediction models with hundreds of overlapping features.
Advantages:
- Reduces overfitting
- Can improve stability when features are strongly correlated
- Improves generalization
Disadvantages:
- Does not eliminate useless features completely (does not set weights to 0)
5. Lasso Regression (L1)
What it is: Performs both regularization and automatic feature selection by using an L1 penalty that can shrink some coefficients exactly to zero.
"Where Ridge is gentle, Lasso is absolutely ruthless. Lasso doesn't just shrink the influence of unhelpful data; it grabs an eraser and deletes it completely by setting the weight to zero. It's immensely satisfying to use Lasso on a messy dataset with 100 confusing features and watch it boldly tell you, "You only actually need these 5 columns.""
Mathematical Formula
Loss = RSS + λ ∑ |w_j|Practical Calculation Example
If Error (RSS)=100, λ=0.1, sum of absolute weights=20.
- Step 1: Penalty = 0.1 × 20 = 2Multiply λ by the sum of absolute coefficient values.
- Step 2: Loss = 100 + 2Add the L1 penalty to RSS.
- Step 3: Loss = 102During fitting, the L1 penalty can drive some coefficients exactly to zero.
Total Computed Loss = 102
Common Applications
Financial distress prediction where identifying exactly which handful of indicators out of thousands matter is the primary goal; medical screening feature selection.
Advantages:
- Automatic feature selection
- Simpler, sparse models
- Can produce sparse models
Disadvantages:
- Can accidentally drop useful correlated variables
- Unstable with highly correlated data
6. Elastic Net Regression
What it is: Combines L1 and L2 penalties so the model can trade off sparsity and coefficient shrinkage.
"Elastic Net blends L1 and L2 regularization. It is especially worth testing when there are many predictors and groups of correlated features."
Mathematical Formula
Loss = RSS + λ₁ ∑ |w_j| + λ₂ ∑ (w_j)²Practical Calculation Example
Combines L1 and L2. If RSS=100, L1=20, L2=50.
- Step 1: Choose λ₁ = 0.1 and λ₂ = 0.02Use small example strengths for the L1 and L2 penalties.
- Step 2: L1 penalty = 0.1 × 20 = 2Calculate the L1 contribution.
- Step 3: L2 penalty = 0.02 × 50 = 1Calculate the L2 contribution.
- Step 4: Loss = 100 + 2 + 1 = 103Add RSS and both penalties.
Illustrative Elastic Net objective = 103
Common Applications
Algorithmic trading or big-data portfolio optimization involving numerous highly correlated, volatile stock market indices.
Advantages:
- Combines L1 and L2 regularization
- Can be useful when predictors are correlated
Disadvantages:
- More hyperparameters to tune
- Computationally slightly heavier
7. Decision Tree Regression
What it is: Splits data into branches based on feature conditions to generate predictions at the leaf nodes.
"Let's throw out the complex math equations for a second. A Decision Tree is fundamentally just a giant game of "20 Questions." It slices your data based on yes/no questions (e.g., "Is it located in the city center?"). I deeply love decision trees because you can literally print them out and explain exactly how the AI made its choice to a non-technical CEO. Sadly, heavily overgrown decision trees are terribly delicate and prone to overfitting."
Practical Calculation Example
Evaluating conditions step-by-step top down:
IF (Area > 1500) AND IF (Bedrooms > 3) THEN Prediction = ₹75LFinal Leaf Output = ₹75L
Common Applications
Business strategic planning analysis, estimating patient recovery times via conditional medical factors, interpreting conditional risk paths.
Advantages:
- Easy visualization and human interpretation
- No feature scaling normally required
Disadvantages:
- Deep trees can overfit without constraints
- Unstable to small data changes
8. Random Forest Regression
What it is: Combines many varied decision trees together. The final prediction is the mathematical average of all trees' predictions.
"If one tree makes mistakes, combining many trees can make the overall prediction more stable. Random Forest averages the predictions of many varied trees, which often reduces the variance of a single deep tree. It is a useful tabular baseline, but validation is still needed."
Practical Calculation Example
Three separate parallel decision trees output different predictions for the same data:
Prediction = Average(Tree1: 70, Tree2: 80, Tree3: 75)Ensemble Prediction = 75
Common Applications
Predicting equipment failure maintenance timing in factories, evaluating loan risk scores based on varied historical financial behaviors.
Advantages:
- Often a strong tabular baseline
- Averaging many trees often reduces variance compared with one deep tree
- Handles large datasets well
Disadvantages:
- Slower training
- Lost interpretability (Black Box)
- High memory usage
9. Support Vector Regression (SVR)
What it is: Tries to fit the best line within an acceptable mathematical margin boundary (epsilon).
"SVR is bizarre but brilliant. Instead of caring about every single data point perfectly, SVR creates a "tube" of acceptable error along its line. It essentially ignores any data point that lands safely inside this tube. It's highly intellectual and shines mathematically when working in insanely high-dimensional spaces (like text analysis), though tuning it can sometimes feel like a dark art."
Practical Calculation Example
If margin ε=3, Actual=50, Predicted=48:
Error Margin = |50-48| = 2. Since 2 <= 3 (ε)Prediction is inside margin safely = 0 Loss penalty!
Common Applications
Processing highly dense time-series data for electrical grid load forecasting or forecasting in extreme high-dimensional text data processing.
Advantages:
- Works well with high-dimensional data
- Uses an epsilon-insensitive loss that ignores sufficiently small errors
Disadvantages:
- Kernel SVR can become slow as sample size grows
- Performance can be sensitive to kernel, C, epsilon, and scaling
10. KNN Regression
What it is: Predicts values by looking at the target values of the 'K' nearest, most similar neighboring data points, and averaging them.
"KNN is beautifully lazy. During the "training" phase, it mathematically does nothing except memorize the dataset. When you ask it for a prediction, it just looks around for its 'K' most similar neighbors and averages them out. It heavily mimics how human real-estate agents price houses (by looking at "comps"). It's wonderfully intuitive but disastrously slow if you have millions of rows."
Practical Calculation Example
If K=3. You find the 3 closest houses to the target house. Their prices: 40L, 42L, 44L.
Prediction Average = (40 + 42 + 44) / 3Predicted Output = 42L
Common Applications
Local property price estimations (similar nearby properties), baseline collaborative filtering or local-trend estimation in recommendation systems.
Advantages:
- Simple algorithm conceptually
- Very little model-building work during fit; training mostly stores the data
Disadvantages:
- Prediction can become slow on large training sets
- Sensitive to irrelevant features
11. Bayesian Regression
What it is: Uses probability distributions to estimate coefficients instead of fixed absolute parameter values, providing uncertainty estimates.
"Most algorithms act like arrogant know-it-alls, giving you a singular, absolute answer like "The price is $50,000." Bayesian Regression is beautifully humble. It admits its uncertainty. It will tell you: "I am 95% confident the price is between $45k and $55k." This ability to mathematically express doubt makes it the absolute holy grail for medical or financial predictions where being confidently wrong is dangerous."
Practical Calculation Example
Instead of outputting absolute '50L', outputs a distribution:
Mean Prediction = 50L. Standard Deviation = 5L.Illustrative interval: about 40L to 60L if a roughly normal predictive distribution makes ±2 standard deviations appropriate.
Common Applications
Predicting uncertain medical outcomes where confidence intervals are critical, analyzing real estate price trends dynamically over time.
Advantages:
- Can represent parameter and prediction uncertainty probabilistically
- Robust for small datasets
- Priors can regularize estimates
Disadvantages:
- Computationally heavy mathematics
- Hard mathematical theory to grasp
12. Gradient Boosting Regression
What it is: Builds a sequence of models sequentially. Each new model specifically attempts to correct the 'Errors' made by previous models.
"Imagine taking an exam, missing a few questions, and then only studying the exact concepts you failed for the next try. That's Gradient Boosting. It trains a sequence of weak models, where every new model is aggressively hyper-focused on fixing the residual errors of the previous one. It is sequential by design and can perform strongly when its complexity is tuned carefully."
Practical Calculation Example
Model 1 Predicts 40 (Actual=50). Error is +10. Model 2 trains purely on 'Error'.
Model 2 predicts Error = 8. Final = M1(40) + M2(8)Combined Output = 48 (Closer to 50!)
Common Applications
Online advertising Click-Through Rate (CTR) estimation, pinpointing anomaly detection probabilities in massive banking streams.
Advantages:
- Can achieve strong accuracy on many structured problems
- Handles highly complex hidden relationships
Disadvantages:
- Slow training process (Sequential)
- Hyperparameter tuning is tricky
- Can overfit easily if unchecked
13. XGBoost Regression
What it is: A highly engineered gradient-boosting implementation with regularization and system optimizations.
"XGBoost became famous for strong performance on many structured-data competitions and remains an important boosting method. It extends gradient boosting with regularization and engineering optimizations. It can be a strong option for structured data, but it should still be compared with simpler baselines and other ensemble methods."
Practical Calculation Example
Optimized boosting loop using second-order derivatives (Hessians).
Final Pred = Sum(learning_rate * tree_predictions)Illustrates how predictions are combined across boosted trees; actual speed depends on data, parameters, and hardware.
Common Applications
Dominating high-stakes structured tabular data tasks (Kaggle competitions), high-volume rapid customer churn probability modeling.
Advantages:
- Often performs strongly on structured/tabular data
- Fast computation via parallel processing
- Auto-handles missing values natively
Disadvantages:
- Complex parameter tuning
- Harder interpretation (Black Box)
14. Neural Network Regression
What it is: Uses deep learning hidden layers with activation functions to model incredibly complex, non-linear mathematical relationships.
"Neural networks use layers of connected units to learn nonlinear functions. for many small structured datasets, simpler models or tree ensembles can be easier to train and explain. But when you are predicting values based on unstructured chaos—like images, audio waves, or massive paragraphs of text—neural networks can learn useful nonlinear representations that simpler models may miss."
Practical Calculation Example
Inside a single neuron node: w₁=0.5, x₁=10, w₂=0.2, x₂=20, bias=1
Node Output = 0.5(10) + 0.2(20) + 1 = 5 + 4 + 1Neuron Activated Value = 10
Common Applications
Predicting global energy consumption limits from large numbers of IoT sensors, autonomous driving path prediction coordinates.
Advantages:
- Can model highly complex nonlinear patterns
- Can benefit from large datasets when the architecture matches the problem
Disadvantages:
- Can require substantial data depending on the problem and architecture
- Can be computationally expensive to train
- Usually less directly interpretable than simple linear models or small trees
Evaluation Metrics for Regression
1. Mean Absolute Error (MAE)
Measures the average of the absolute mathematical differences between actual and predicted values.
Simple intuition: MAE answers, “On average, how far are the predictions from the actual values?” It stays in the same unit as the target, which often makes it easy to explain to non-technical readers.
MAE = (1/n) * Σ |y - y_pred|- |10 − 12| = 2 — first absolute error.
- |20 − 18| = 2 — second absolute error.
- 2 + 2 = 4 — add the absolute errors.
- 4 ÷ 2 = 2 — divide by two predictions.
2. Mean/Root Mean Squared Error (MSE / RMSE)
Penalizes large errors heavily by squaring the differences. RMSE is the square root of MSE.
Simple intuition: Squaring gives larger errors more influence. RMSE then takes the square root so the final value is back in the same unit as the target. It is useful when large mistakes deserve extra attention.
MSE = (1/n) * Σ (y - y_pred)²
RMSE = √MSE- Errors: 10 − 12 = −2 and 20 − 18 = 2.
- Square them: (−2)² = 4 and 2² = 4.
- MSE = (4 + 4) ÷ 2 = 4.
- RMSE = √4 = 2.
3. R-Squared Score (R²)
Compares your model with a simple baseline that always predicts the mean target value. A score of 1.0 is perfect; around 0 means the model is doing about as well as that mean baseline; and R² can even be negative when the model performs worse than the baseline.
Simple intuition: Higher is generally better on the same problem, but R² should be read together with error metrics such as MAE or RMSE and with validation/test performance.
R² = 1 - ( SS_res / SS_tot )SS_res = 2 and SS_tot = 10.- SS_res ÷ SS_tot = 2 ÷ 10 = 0.2
- R² = 1 − 0.2
- R² = 0.8
Regression Algorithm Comparison Table
Here is a quick classroom-level comparison of popular regression algorithms. Treat labels such as “low”, “medium”, and “high” as rough tendencies, not fixed properties—real behaviour depends on the dataset, preprocessing, hyperparameters, and validation setup.
| Algorithm | Linear/Nonlinear | Feature Selection | Overfitting Risk | Speed | Interpretability |
|---|---|---|---|---|---|
| Linear Regression | Linear | No | Medium | Fast | High |
| Polynomial Regression | Nonlinear | No | High | Medium | Medium |
| Ridge Regression | Linear | No | Low | Fast | Medium |
| Lasso Regression | Linear | Yes | Low | Fast | Medium |
| Decision Tree | Nonlinear | Partial | High | Medium | High |
| Random Forest | Nonlinear | Partial | Low | Medium | Low |
| SVR | Nonlinear | No | Low | Slow | Low |
| KNN Regression | Nonlinear | No | Medium | Slow | Medium |
| XGBoost | Nonlinear | Partial | Low | Medium | Low |
| Neural Network | Nonlinear | No | Medium | Slow | Very Low |
When to Use Which Regression Algorithm?
Use the table below as a starting point for experiments, then compare candidate models with validation or cross-validation rather than choosing from a rule alone.
| Situation / Scenario | Recommended Algorithm |
|---|---|
| Simple linear relationship | Linear Regression |
| Many correlated features | Ridge Regression |
| Need automatic feature selection | Lasso Regression |
| Complex nonlinear data | Random Forest / XGBoost |
| Strong tabular baseline worth testing | Gradient Boosting / XGBoost / Random Forest |
| Small-to-medium structured datasets | Start simple; compare Linear / Ridge / SVR / Trees |
| Large or unstructured inputs where representation learning helps | Neural Networks may be appropriate |
Python Implementation Example (Scikit-Learn)
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics import mean_squared_error- numpy: Used to create and manipulate numerical arrays.
- train_test_split: Function to split our data reproducibly into training and evaluation sets.
- Algorithms: We import the specific mathematical models we wish to use.
- mean_squared_error: Our evaluation metric to check model accuracy.
# House Sizes (Independent variable 'X')
X = np.array([[1000], [1500], [2000], [2500], [3000]])
# Output Prices (Dependent variable 'y')
y = np.array([30, 45, 60, 75, 90])
# Split: 80% Train, 20% Test
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=42
)- X & y: We feed in paired coordinates. For example, a 1000 sq ft house is 30 lakhs. Note the exact linear relationship here (Price = Size * 0.03).
- test_size=0.2: Keeps 20% of the data hidden from the model during training so we can test its true predictive power later.
# Initialize Models
lr_model = LinearRegression()
rf_model = RandomForestRegressor(n_estimators=100, random_state=42)
# Train (.fit)
lr_model.fit(X_train, y_train)
rf_model.fit(X_train, y_train)
# Predict (.predict)
lr_pred = lr_model.predict(X_test)
rf_pred = rf_model.predict(X_test)
# Calculate RMSE
lr_rmse = np.sqrt(mean_squared_error(y_test, lr_pred))
rf_rmse = np.sqrt(mean_squared_error(y_test, rf_pred))
print(f"Linear Regression RMSE: {lr_rmse:.2f}")
print(f"Random Forest RMSE: {rf_rmse:.2f}")- .fit(): This is where the actual mathematical learning happens. The model finds the best coefficients.
- .predict(): Once trained, we generate predictions on the hidden
X_testset. - RMSE: We compare the real answers
y_testagainst our model's predictions. Lower score is better!
Terminal Output & Analysis
$ python regression_example.py Linear Regression RMSE: 0.00 Random Forest RMSE: 4.65
Linear Regression gets 0.00 here because the tiny sample follows an exact straight-line rule (Price = Size × 0.03). With
random_state=42, the Random Forest predicts the single held-out point less precisely, giving RMSE 4.65.Important: this test set contains only one row, so the comparison is for learning the workflow—not for deciding which algorithm is generally “better”.Common Regression Questions
Is regression only Linear Regression?
No. Linear Regression is one method. Trees, Random Forests, boosting, KNN, SVR, Bayesian models, and neural networks can also perform regression.
Can regression predict Pass or Fail?
Usually that is a classification problem because the answer is a category. Regression would instead predict a numerical value such as marks or salary.
Should I start with the most powerful algorithm?
No. Start with a simple baseline, then test more complex models only when they provide a meaningful validated improvement.
Which topic should I learn next?
Continue with Linear Regression, then learn Gradient Descent, Ridge Regression, and Lasso Regression.
Final Summary
Regression algorithms are a major part of supervised predictive modelling. They are used when the target is numerical, such as a price, demand level, temperature, duration, or other continuous measurement.
From highly interpretable linear models to immensely powerful non-linear tree ensembles and deep neural networks, the practical goal is to start with a sensible baseline, compare models fairly on validation data, and choose a level of complexity that generalizes well.
Most Important Insight to Remember:
Regression learns relationships between input features and a numerical target so that we can estimate values for new data. A good regression model is not the most complicated one—it is one that makes useful predictions on data it has not seen before.