Skip to content
New
Latest News || 7 October 2026: Quiz and Pizza Night — Titanic Crew placed fourth. || 3 October 2026: Serving as a Student Ambassador at Queen's University Belfast, welcoming prospective students and visitors and supporting EEECS tours and event activities. || 9 September 2026: Published at AP-S/URSI 2026: “Near Field-Aware UE Localization in RIS-Aided Wireless Networks Through ML-Regressor.” || 25 August 2026: Poster presentation at UCMMT 2026 in Birmingham — “Experimental Validation of Localisation in RIS-Assisted mmWave Networks.” || 18 August 2026: Published at EuCAP 2026: “Impact of RIS Size on Machine Learning-Enabled Beam Sweeping for User Localization.”
Knowledge Hubmachine learningRegression Algorithms

machine learning learning note

Regression Algorithms

A deeper explanation of regression models for predicting continuous values, with intuition, assumptions, and practical guidance.

What is Regression?

Regression is a supervised learning task where the target is a continuous numerical value. Instead of predicting a class such as "spam" or "not spam", a regression model predicts a quantity.

Examples:

  • House price in pounds.
  • Temperature tomorrow.
  • Received signal strength.
  • Localization error in meters.
  • Battery lifetime in hours.

The central question is: "Given these input features, what number should the model predict?"

References for this section3

Regression vs. Classification

QuestionTask
Is this email spam?Classification
What is the price of this house?Regression
Which modulation type is this?Classification
What is the expected channel gain?Regression
References for this section3

1. Linear Regression

Linear regression is the simplest and most interpretable regression model. It assumes the output can be approximated by a weighted sum of the input features.

Linear regression picture
observed points -> best-fit line -> numeric prediction

Concept adapted from Tpoint Tech/Javatpoint linear-regression explanations and standard regression diagrams.

References for this section3

Intuition

For one feature:

ŷ = β₀ + β₁x

For many features:

ŷ = β₀ + β₁x₁ + β₂x₂ + ⋯ + βₚxₚ

Training finds weights that minimize the difference between predicted and true values, often using mean squared error.

References for this section3

Strengths

  • Very fast.
  • Easy to interpret.
  • Good baseline.
  • Can extrapolate outside the training range.
References for this section3

Weaknesses

  • Assumes a mostly linear relationship.
  • Sensitive to outliers.
  • Cannot naturally model complex feature interactions.
References for this section3

Best Use Cases

  • Quick baselines.
  • Scientific modeling where interpretability matters.
  • Problems with approximately linear relationships.
References for this section3

2. Ridge and Lasso Regression

Ridge and Lasso are regularized versions of linear regression. They add a penalty to discourage overly large weights.

References for this section3

Ridge Regression

Ridge uses an L2 penalty. It shrinks weights smoothly and is useful when many features are correlated.

Equation-style view:

Linear Regression
minimize   Σᵢ(yᵢ − ŷᵢ)²
Ridge Regression
minimize   Σᵢ(yᵢ − ŷᵢ)² + λΣⱼβⱼ²
The second term is the L2 penalty that discourages large coefficients.

In simple words, Ridge fits the data while keeping the weights from becoming unnecessarily large. This often makes the model more stable on new data.

References for this section3

Lasso Regression

Lasso uses an L1 penalty. It can push some weights exactly to zero, which makes it useful for feature selection.

Lasso Regression
minimize   Σᵢ(yᵢ − ŷᵢ)² + λΣⱼ|βⱼ|
The second term is the L1 penalty that can shrink some coefficients exactly to zero.
References for this section3

Why Regularization Matters

Without regularization, a model may fit noise in the training data. Regularization makes the model simpler and often improves generalization.

References for this section3

3. K-Nearest Neighbors Regressor

KNN regression predicts a number by averaging the target values of nearby training examples.

References for this section3

Intuition

If a new house is similar to five nearby houses in the dataset, KNN predicts the average price of those five houses.

References for this section3

Strengths

  • Simple and non-parametric.
  • Can model non-linear relationships.
  • No explicit training phase.
References for this section3

Weaknesses

  • Slow prediction for large datasets.
  • Sensitive to feature scaling.
  • Performs poorly when irrelevant features dominate distance.
References for this section3

Best Use Cases

  • Small datasets.
  • Local interpolation problems.
  • Situations where similar inputs should have similar outputs.
References for this section3

4. Polynomial Regression

Polynomial regression extends linear regression by adding powers of features, such as x^2, x^3, and interactions.

References for this section3

Intuition

A straight line cannot fit a curved trend. Polynomial features allow a linear model to fit curves.

ŷ = β₀ + β₁x + β₂x² + β₃x³
References for this section3

Strengths

  • Captures simple curves.
  • Still relatively interpretable.
  • Easy to implement.
References for this section3

Weaknesses

  • High-degree polynomials can overfit badly.
  • Extrapolation can become unrealistic.
  • Feature scaling becomes important.
References for this section3

5. Support Vector Regression

Support Vector Regression (SVR) is related to SVM classification. Instead of separating classes, it tries to fit a function while ignoring small errors inside a margin.

References for this section3

Intuition

SVR draws a tube around the prediction function. Errors inside the tube are acceptable. The model focuses mainly on points outside the tube.

References for this section3

Strengths

  • Robust to small noise.
  • Kernel functions allow non-linear regression.
  • Useful for medium-sized datasets.
References for this section3

Weaknesses

  • Can be slow for large datasets.
  • Requires tuning kernel, margin, and regularization parameters.
  • Less interpretable than linear regression.
References for this section3

6. Decision Tree Regressor

A decision tree regressor splits the feature space into regions and predicts the average target value in each region.

References for this section3

Intuition

For house prices, a tree may first split by location, then by area, then by number of rooms. Each final leaf stores an average price.

References for this section3

Strengths

  • Handles non-linear relationships.
  • Easy to visualize.
  • Minimal preprocessing.
References for this section3

Weaknesses

  • Can overfit if too deep.
  • Predictions are piecewise constant.
  • Single trees are unstable.
References for this section3

7. Random Forest Regressor

Random forest regression averages predictions from many decision trees.

References for this section3

Intuition

Each tree makes a different estimate. Averaging many trees reduces variance and gives a more stable prediction.

References for this section3

Strengths

  • Strong tabular-data baseline.
  • Handles feature interactions.
  • Less overfitting than one decision tree.
  • Works with minimal preprocessing.
References for this section3

Weaknesses

  • Less interpretable than one tree.
  • Cannot extrapolate beyond the training target range.
  • Larger memory footprint.
References for this section3

8. Gradient Boosting and XGBoost Regressor

Gradient boosting builds trees sequentially. Each new tree learns to correct the residual errors of the current model.

References for this section3

Intuition

If the model underpredicts one group of samples, the next tree focuses on reducing that underprediction. Over many rounds, the model becomes a strong predictor.

References for this section3

Strengths

  • Often excellent on structured data.
  • Captures non-linear relationships.
  • Works well with mixed feature types.
  • XGBoost adds regularization and scalable training.
References for this section3

Weaknesses

  • Needs careful tuning.
  • Can overfit if trees are too deep or learning rate is too large.
  • Training is more sequential than random forest.
References for this section3

Regression Metrics

References for this section3

Mean Absolute Error

Mean Absolute Error (MAE) is the average absolute difference between prediction and true value. It is easy to interpret because it uses the same unit as the target.

MAE = (1/n)Σᵢ|yᵢ − ŷᵢ|
References for this section3

Mean Squared Error

Mean Squared Error (MSE) squares the errors before averaging. Large errors are punished more strongly.

MSE = (1/n)Σᵢ(yᵢ − ŷᵢ)²
References for this section3

Root Mean Squared Error

Root Mean Squared Error (RMSE) is the square root of MSE. It is also in the same unit as the target.

RMSE = √((1/n)Σᵢ(yᵢ − ŷᵢ)²)
References for this section3

R-squared

R-squared measures how much variance in the target is explained by the model. It is useful, but it should not be the only metric.

R² = 1 − Σᵢ(yᵢ − ŷᵢ)² / Σᵢ(yᵢ − ȳ)²
References for this section3

Practical Checklist

  • Plot predicted values vs. true values.
  • Check residuals for patterns.
  • Scale features for KNN, SVR, linear models, and neural networks.
  • Use cross-validation when data is limited.
  • Compare against a simple baseline, such as predicting the mean.
  • Watch out for outliers, data leakage, and target leakage.
References for this section3

Python: Load Common Regressors

Regressors follow the same scikit-learn pattern as classifiers:

  • fit(X_train, y_train) learns the mapping.
  • predict(X_test) returns continuous values.
  • Metrics such as MAE, RMSE, and R-squared evaluate the predictions.
from sklearn.linear_model import LinearRegression, Ridge, Lasso
from sklearn.neighbors import KNeighborsRegressor
from sklearn.tree import DecisionTreeRegressor
from sklearn.svm import SVR
from sklearn.ensemble import RandomForestRegressor, GradientBoostingRegressor

regressors = {
    "linear": LinearRegression(),
    "ridge": Ridge(alpha=1.0),
    "lasso": Lasso(alpha=0.01),
    "knn": KNeighborsRegressor(n_neighbors=5),
    "decision_tree": DecisionTreeRegressor(max_depth=6, random_state=42),
    "svr": SVR(kernel="rbf"),
    "random_forest": RandomForestRegressor(n_estimators=200, random_state=42),
    "gradient_boosting": GradientBoostingRegressor(random_state=42),
}
References for this section3

Python: Compare Regressors on One Dataset

from sklearn.datasets import fetch_california_housing
from sklearn.model_selection import train_test_split
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_absolute_error, r2_score

X, y = fetch_california_housing(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

for name, reg in regressors.items():
    model = make_pipeline(StandardScaler(), reg)
    model.fit(X_train, y_train)
    pred = model.predict(X_test)

    print(
        name,
        "MAE=", round(mean_absolute_error(y_test, pred), 3),
        "R2=", round(r2_score(y_test, pred), 3),
    )
References for this section3

Python: Save and Load a Regressor

import joblib

final_regressor = RandomForestRegressor(
    n_estimators=300,
    max_depth=None,
    random_state=42,
    n_jobs=-1
)
final_regressor.fit(X_train, y_train)

joblib.dump(final_regressor, "regressor.joblib")

loaded_regressor = joblib.load("regressor.joblib")
print(loaded_regressor.predict(X_test[:5]))
References for this section3

Takeaway

Regression predicts numbers. Linear models are fast and interpretable, tree ensembles are strong for tabular data, and kernel or neural methods help with complex non-linear patterns. The best model depends on the data shape, required interpretability, and error cost.

References for this section3

Complete references and further reading