Regression in machine learning is a supervised learning technique used to predict continuous numerical values by learning relationships between input variables (features) and an output variable (target). It helps understand how changes in one or more factors influence a measurable outcome and is widely used in forecasting, risk analysis, decision-making and trend estimation.
- Works with real-valued output variables
- Helps to identify strengths and the type of relationships
- Supports both simple and complex predictive models.
- Used for tasks like price prediction, trend forecasting and risk scoring.
Types of Regression
Regression can be classified into different types based on the number of predictor variables and the nature of the relationship between variables:
1. Simple Linear Regression: A statistical technique that models the relationship between a single independent variable and a continuous dependent variable by fitting a straight line (best-fit line) that minimizes the sum of squared errors. It assumes a constant rate of change, meaning the output changes proportionally whenever the input changes.
- Application: Estimating house price from only its size
- Advantage: Highly interpretable due to its simple mathematical structure
- Disadvantage: Cannot capture curved or complex data patterns
2. Multiple Linear Regression: An extension of simple linear regression that models the linear relationship between multiple input variables and a continuous target. The model assigns weights (coefficients) to each feature, quantifying how strongly each variable affects the outcome while holding others constant.
- Application: Predicting house prices using multiple factors like size, location, age and number of rooms
- Advantage: Captures the combined influence of many factors simultaneously
- Disadvantage: Performance drops in the presence of multicollinearity (features highly correlated with each other)
3. Polynomial Regression: A form of regression where the relationship between the independent variable(s) and dependent variable is modelled as an nth-degree polynomial. It transforms input features into higher-order terms (e.g., x², x³), enabling the model to represent curvature and complex non-linear patterns in the data.
- Application: Modelling curved growth trends like population increase or temperature variation
- Advantage: Effectively captures non-linear relationships without switching to non-linear algorithms
- Disadvantage: Higher-degree polynomials may lead to overfitting and unstable predictions
4. Ridge & Lasso Regression: Regularization techniques built on linear regression that add penalty terms to the loss function to prevent large coefficients.
Ridge adds an L2 penalty, shrinking coefficients smoothly. Lasso adds an L1 penalty, which can shrink some coefficients to zero, performing feature selection. Both help stabilize models when dealing with many features or noisy data.
- Application: Used in high-dimensional datasets like marketing attribution or gene expression data
- Advantage: Controls overfitting and improves generalization, especially with many predictors
- Disadvantage: Penalty terms make model interpretation less straightforward
5. Support Vector Regression (SVR): A regression method based on Support Vector Machines, which tries to fit the best possible line within a defined margin (epsilon-tube) around the data. Rather than minimizing prediction error for every point, SVR focuses on points outside this margin, using kernel functions to model both linear and non-linear relationships.
- Application: Predicting continuous outcomes such as stock values or energy consumption
- Advantage: Works well with high-dimensional, complex datasets and non-linear patterns
- Disadvantage: Computationally intensive and requires careful tuning of kernels and parameters
6. Decision Tree Regression: A non-linear regression technique that splits the data into branches based on feature thresholds. Each internal node represents a decision question and leaf nodes represent predicted continuous values. It learns patterns by recursively partitioning the data to minimize prediction errors.
- Application: Predicting customer spending behavior based on demographic and financial features
- Advantage: Easy to visualize and understand decision logic
- Disadvantage: Easily overfits, especially when the tree becomes deep and complex
7. Random Forest Regression: An ensemble technique that builds multiple decision trees on different subsets of data and averages their predictions. This reduces the overfitting tendency of single trees and improves accuracy through diversity (bagging). Each tree captures a slightly different aspect of the data.
- Application: Sales forecasting, demand planning, churn prediction
- Advantage: High accuracy and robust performance even on noisy datasets
- Disadvantage: Acts as a black-box model, making interpretation difficult due to many trees
Regression Evaluation Metrics
Evaluation in machine learning measures the performance of a model. Here are some popular evaluation metrics for regression:
- Mean Absolute Error (MAE): The average absolute difference between the predicted and actual values of the target variable.
- Mean Squared Error (MSE): The average squared difference between the predicted and actual values of the target variable.
- Root Mean Squared Error (RMSE): Square root of the mean squared error.
- Huber Loss: A hybrid loss function that transitions from MAE to MSE for larger errors, providing balance between robustness and MSE’s sensitivity to outliers.
- R2 – Score: Higher values indicate better fit ranging from 0 to 1.
Regression Model Machine Learning
Let's take an example of linear regression. We have a Housing data set and we want to predict the price of the house. Following is the python code for it.
You can download dataset from here.
import pandas as pd
from sklearn import linear_model
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('Agg')
df = pd.read_csv("Housing.csv")
Y = df['price']
X = df['lotsize']
X = X.to_numpy().reshape(len(X), 1)
Y = Y.to_numpy().reshape(len(Y), 1)
X_train = X[:-250]
X_test = X[-250:]
Y_train = Y[:-250]
Y_test = Y[-250:]
plt.scatter(X_test, Y_test, color='black')
plt.title('Test Data')
plt.xlabel('Size')
plt.ylabel('Price')
plt.xticks(())
plt.yticks(())
regr = linear_model.LinearRegression()
regr.fit(X_train, Y_train)
plt.plot(X_test, regr.predict(X_test), linewidth=3, color='red')
plt.savefig("regression_plot.png")
print("Plot saved as regression_plot.png")
Output:

Here in this graph we plot the test data. The red line indicates the best fit line for predicting the price.
Applications
- Predicting prices: Used to predict the price of a house based on its size, location and other features.
- Forecasting trends: Model to forecast the sales of a product based on historical sales data.
- Identifying risk factors: Used to identify risk factors for heart patient based on patient medical data.
- Making decisions: It could be used to recommend which stock to buy based on market data.


