Introduction to Machine Learning
Regression

Introduction to Regression

Introduction

Regression is a method in machine learning that focuses on predicting numerical values based on input features. For example, consider a scenario where we predict the sales price of a house based on its features, such as the square footage, number of bedrooms, and location. We can train a regression model to learn the relationship between these variables by collecting data on past house sales, including the features and the corresponding sale prices. Once trained, the model can be used to estimate the price of a new house by providing its features as input.

Regression enables us to uncover patterns and make informed predictions in various domains, from predicting sales figures in business to estimating medical outcomes in healthcare.

Definition

Regression is a supervised learning technique that aims to learn a function that maps input features to a continuous target variable. The goal is to find the best-fit line or curve that minimizes the difference between predicted and actual values.

The key components of a regression problem are:

  • Input Features: The independent variables used to make predictions are denoted as XX.
  • Target Variable: The continuous dependent variable we aim to predict is yy.
  • Model: The mathematical function maps the input features to the target variable, denoted as f(X)f(X).
  • Parameters: The coefficients or weights that define the model's behavior learned during training.
  • Loss Function: A measure of how well the model fits the training data, typically mean squared error (MSE) for regression.

Given a dataset D=(x1,y1),(x2,y2),...,(xn,yn)D = {(x_1, y_1), (x_2, y_2), ..., (x_n, y_n)} consisting of nn data points, where xix_i represents the inputs and yiy_i represents the output, the goal of regression is to learn a function f(X)f(X) that minimizes the loss function. The most common loss function for regression is the mean squared error (MSE):

MSE=1ni=1n(yif(xi))2\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} (y_i - f(x_i))^2

Where:

  • nn is the number of data points,
  • yiy_i is the actual value of the target variable for the ii-th data point,
  • f(xi)f(x_i) is the predicted value of the target variable for the ii-th data point.
  • Mean Squared Error (MSE) is a commonly used performance metric in machine learning, particularly for regression problems. It measures the average squared difference between the predicted values and the actual values. MSE provides a way to quantify the amount of error or deviation in the predictions made by a model.

The goal is to find the function f(X)f(X) that minimizes the MSE, making the predictions as close as possible to the actual values.

Types of Regression

Some popular regression types are:

Linear Regression

Linear regression is a simple and widely used method for predicting an output based on one or more input features. It assumes a linear relationship between the inputs and the output. In other words, Linear regression assumes the relationship between inputs and output is a straight line. The equation looks like this:

y=β0+β1x1+...+βnxny = \beta_0 + \beta_1x_1 + ... + \beta_nx_n

Where:

  • yy is the output we want to predict,
  • x1,...,xnx_1, ..., x_n are the inputs (information we have),
  • β0,β1,...,βn\beta_0, \beta_1, ..., \beta_n are numbers that the regression learns to make the line fit the data best.

Example: Now, let us consider an example of predicting a person's salary based on their years of experience and education level:

Salary=β0+β1×experience+β2×education\text{Salary} = \beta_0 + \beta_1 \times \text{experience} + \beta_2 \times \text{education}

In this equation:

  • Salary is the target variable (the salary we want to predict),
  • experience is the first input feature (the number of years of work experience),
  • education is the second input feature (the education level, which can be represented as a numeric value, e.g., 1 for high school, 2 for bachelor's degree, 3 for master's degree, etc.),
  • β0\beta_0 is the intercept (the predicted salary when a person has zero years of experience and no education),
  • β1\beta_1 is the coefficient for experience (the change in salary for a one-year increase in experience, holding education level constant),
  • β2\beta_2 is the coefficient for education (the change in salary for a one-level increase in education, holding years of experience constant).

Linear regression finds the best values for β0\beta_0, β1\beta_1, and β2\beta_2 that minimize the difference between the predicted and actual salaries in the training data.

Polynomial Regression

Polynomial regression is an extension of linear regression that allows for modeling non-linear relationships between the input features and the target variable. It achieves this by including polynomial terms of the input features in the regression equation. In short, it uses the same idea as linear regression but includes squared, cubed, or higher powers of the inputs.

The general equation for polynomial regression with one input feature is:

y=β0+β1x+β2x2+...+βnxny = \beta_0 + \beta_1 x + \beta_2 x^2 + ... + \beta_n x^n

Where:

  • yy is the target variable (the value we want to predict),
  • xx is the input feature,
  • β0\beta_0 is the intercept (the value of yy when xx is 0),
  • β1,β2,...,βn\beta_1, \beta_2, ..., \beta_n are the coefficients (the weights associated with each polynomial term),
  • nn is the degree of the polynomial (a positive integer determining the highest power of xx in the equation).

Example: Let us consider an example of predicting a company's sales based on its advertising expenditure:

sales=β0+β1×advertising+β2×advertising2\text{sales} = \beta_0 + \beta_1 \times \text{advertising} + \beta_2 \times \text{advertising}^2

In this equation:

  • sales is the target variable (the company's sales in thousands of dollars),
  • advertising is the input feature (the company's advertising expenditure in thousands of dollars),
  • β0\beta_0 is the intercept (the predicted sales when the advertising expenditure is 0),
  • β1\beta_1 is the coefficient for the linear term (the change in sales for every additional dollar in advertising expenditure),
  • β2\beta_2 is the coefficient for the quadratic term (the change in sales for a one-unit increase in the square of advertising expenditure). In other words, it captures the non-linear effect of every dollar spent on sales.

Polynomial regression finds the best values for β0\beta_0, β1\beta_1, and β2\beta_2 that minimize the difference between the predicted and actual sales in the training data.

Applications

Regression has a wide range of applications across various domains:

  • Dynamic Rates for Lending Pools: Regression can assist in setting dynamic lending rates for isolated lending pools based on volatility, volume and LTV (Loan to value ratio) of the pool.
  • Medical Diagnosis: Regression can assist in predicting patient outcomes, such as the likelihood of a disease or the expected recovery time, based on medical records, symptoms, and test results. These models supports healthcare professionals in making informed treatment decisions.
  • Stock Market Analysis: Regression models can analyze the relationship between stock prices and various economic indicators, such as interest rates, GDP growth, and company financials. Such models aid in making investment decisions and risk assessments.

Conclusion

Regression is a powerful method in an ML practitioner's toolkit to model quantifiable relations between various features. Choosing the appropriate regression algorithm depends on the nature of the problem, the assumptions about the data, and the desired interpretability of the model. Linear regression is simple and interpretable but assumes a linear relationship, while polynomial regression can capture non-linear patterns.

Resources