Linear Regression Model for Prediction
In the next section, we will learn about Logistic Regression-based classification. The logistic regression model builds on top of the Linear regression-based prediction model. This is why in this section, we are going to discuss linear regression-based prediction.
Videos on Linear Regression-based Prediction
Linear Regression Prediction
Linear regression-based prediction is a statistical technique used to predict a particular outcome based on a set of input variables. It is based on the assumption of a linear relationship between the input variables and the outcome. By using linear regression, one can predict the outcome by applying a linear equation to the data, thereby making it possible to predict the outcome with a certain degree of accuracy. Linear regression-based prediction is a powerful technique in many areas, such as finance, marketing, and engineering. It can identify relationships between variables, estimate the impact of changes, and forecast future trends.
To find the coefficients , , , …, in the linear regression equation, we need to use a technique called Ordinary Least Squares (OLS) regression. The goal of OLS regression is to minimize the sum of the squared errors between the predicted values of y and the actual values of y in the training data.
The calculations to find the coefficients are as follows:
- Calculate the mean of each predictor variable () and the response variable ().
where n is the number of observations in the training data, and and are the values of the i-th predictor variable and the response variable, respectively, for the j-th observation.
- Calculate the sample covariance between each predictor variable () and the response variable ().
- Calculate the sample variance of each predictor variable (x_i).
- Calculate the sample correlation coefficient between each predictor variable () and the response variable ().
where is the sample standard deviation of .
- Calculate the coefficients using the following formula:
These calculations assume that the predictor variables are not linearly dependent, and that the errors are normally distributed with constant variance. If these assumptions are not met, the OLS regression results may not be reliable.
Example
Let us work through a simple example to illustrate the calculations for finding the coefficients of a linear regression model using the Ordinary Least Squares method.
Suppose we have a dataset with four predictor variables (x1, x2, x3, x4) and one response variable (y), and 6 observations:
x1 x2 x3 x4 y 2.3 3.5 1.2 0.5 23 1.9 2.7 3.1 2.2 15 3.5 1.1 2.5 1.8 31 2.7 1.9 2.8 1.1 20 2.9 2.2 1.7 1.6 25 1.5 2.6 3.2 2.8 18
We want to fit a linear regression model to predict y from the four predictor variables. That is, we want to calculate the five coefficients (beta values , , , and ).
Step 1: Calculate the mean of each predictor variable and the response variable.
Step 2: Calculate the sample covariance between each predictor variable and the response variable.
Step 3: Calculate the sample variance of each predictor variable.
Step 4: Calculate the sample correlation coefficient between each predictor variable and the response variable.
Step 5: Calculate the coefficients using the following formula.
Therefore, the linear regression equation that best fits this dataset is:
The equation can be used to predict y values for new observations.
For example, suppose we want to predict the value of the response variable y for a new observation with the predictor variables
x1=2.1, x2=3.0, x3=1.8, x4=2.3
We can use the linear regression equation we just calculated to make the prediction:
So the predicted value of y for this new observation is 17.79.
Note that the linear regression model assumes that the relationship between the predictor variables and the response variable is linear and that the errors are normally distributed with constant variance. These assumptions should be checked using diagnostic plots and other techniques to ensure the model’s reliability.