Updated March 14, 2023

## Introduction to Dataset for Linear Regression

The dataset for linear regression is defined as in machine learning it is an algorithm that can be categorized in supervised learning to find the target variable between the dependent variables and the independent variables; also, it can allow us to establish a relationship between those variables which are the best suit for a relationship, in machine learning it can be used to closely relate variables which are related to dependent variables and it can be used for a large amount of data when analyzing the data while constructing the model it can be used to find the anticipated value of the dependent variable.

### What is Dataset for Linear Regression?

- Linear regression is the machine learning algorithm that can be used to construct a model on the dataset for analyzing a large amount of data, and the model of dataset gives the correct anticipate values of the dependent variables, the dependent variable in the regression is the leading element when we are trying to understand the anticipated value and also a directory of the dataset which can accommodate the test data for linear regression is called as a regression.
- The linear regression is maybe the most familiar and recognizable algorithm in statistics and in machine learning; basically, the linear regression is come out for the statistic field, but after further studies, it as a model while understanding the relationship between the input numerical variable and output numerical variable it has been taken by the machine learning algorithm, the relationship between the variables may be positive or negative in nature in which the positive relationship can happen when both the variables that are independent variables and dependent variables increases in a graphical manner and the negative relationship happens when the dependent variable decreases and independent variable increases.
- Linear regression has two types: simple linear regression, which is necessary to give anticipate response to the values using its simple feature, and multiple linear regressions, which are used when having a large amount of data to predict the response value by using two or more features of it.

### Basics of Linear Regression and Implementation

In the basics of linear regression anticipates the one variable from the second variable. The criteria variables it uses is the predicted variable when we are trying to anticipate the one variable. It is called simple regression, and when we are trying to anticipate one or more variables, it is called multiple linear regression. The dataset model have some features to make the dataset flexible and powerful when we implement a simple linear regression; we have to consider that two variables are linearly related and in the response of it gives the accurate value as per its features if we have dataset m and n with values of response for each value in n in response for values in m.

If m as a m = [m_1, m_2,……,m_n] and n as a n = [n_1,n_2,…….n_n]

While this example is about to find the n number of observations, when we plot the graph between these, then we will have to find the best line which is fitted to find the predicted value.

### How to Use Dataset for Linear Regression?

- When we have multiple input variables, then we can use the multiple linear regression techniques and also we can use different techniques to perform linear regression on the dataset, as we know the linear regression technique is used to find the linear relationship between the selected values and to find the one or more anticipated values.
- In machine learning, linear regression is the statistical model that can come under the class of supervised learning algorithm, and we can use this algorithm which is not used to predict the output from different logistic regression but is used for forecasting the values which have a separate output which can happen in the classification in machine learning.
- Let us see an example that we have a dataset of patients who are diagnosed for having blood pressure with their ages and respective weight for each patient and from this; we want to anticipate or predict the new patients which will come for the blood pressure problem so such type of data we need to put in a table format so in linear regression the first table of data is called as a dataset of independent variables because that variable can be explained and we can match that variables with the predicted variables and the predicted dataset will be called as a dataset of dependent variables because this variable can explain with the input variables like age and weight in our given an example.

### Example of Dataset for Linear Regression

Different examples are mentioned below:

Python example for simple linear regression.

**Code:**

`from __future__ import division`

import numpy as np

import matplotlib.pyplot as plt

import pandas as pd

def estimate_coef(x, y):

n = np.size(x)

m_x = np.mean(x)

m_y = np.mean(y)

SS_xy = np.sum(y*x) - n*m_y*m_x

SS_xx = np.sum(x*x) - n*m_x*m_x

b_1 = SS_xy / SS_xx

b_0 = m_y - b_1*m_x

return (b_0, b_1)

def plot_regression_line(x, y, b):

plt.scatter(x, y, color = "m",

marker = "o", s = 30)

y_pred = b[0] + b[1]*x

plt.plot(x, y_pred, color = "g")

plt.xlabel('x')

plt.ylabel('y')

plt.show()

def main():

x = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])

y = np.array([1, 3, 2, 5, 7, 8, 8, 9, 10, 12])

b = estimate_coef(x, y)

print("Estimated coefficients:\nb_0 = {} \

\nb_1 = {}".format(b[0], b[1]))

plot_regression_line(x, y, b)

if __name__ == "__main__":

main()

**Output:**

Above is the example of implementing the simple linear regression in python to find anticipated value.

### Conclusion

In this article, we conclude that the linear regression model can be created by using the linear and the non-linear relationship between the dependent and independent variables; also, we have seen some points, so if anyone wants to understand the concept of the dataset for linear regression then this article will be definitely helpful.

### Recommended Articles

This is a guide to Dataset for Linear Regression. Here we discuss the introduction, basics of linear regression and implementation, use & example. You may also have a look at the following articles to learn more –