machine-learning-multiple-regression

Introduction to Machine Learning Multiple Regression

In This Article, You Will Learn About Multiple Regression.

Machine Learning Multiple Regression – Before moving ahead, let’s take a look at Introduction to Machine Learning Polynomial Regression.

Multiple Regression

Multiple Regression is a regression that predict future value based on multiple variables. 

How Does It Work?

In Python, we can do start with Pandas module.

The Pandas module allows to read csv file and return a DataFrame object.

Example: Import necessary module to create multiple regression.

Table of Contents

				
					import pandas as pd
from sklearn import linear_model

file_read = pd.read_csv('file.csv')      # file read

X = file_read[["Weight", "Roll_No"]]     # independent value
y = file_read["ID"]                      # dependent value

regression = linear_model.LinearRegression()
regression.fit(X, y)                     # create linear object

# predict the Weight of a student where the Roll_No is 100, and the ID is 1000:
predictIDvalue = regression.predict([[100, 1000]])

print(predictIDvalue)

				
			
				
					Output - 

[76.69555739]
				
			

In the final analysis, it returned predicted value of variable ‘ID.’

Click to Download File.

Here’s the brief explanation of above mentioned code.

In lines 1 and 2,

Imported Pandas and sklearn module to create multiple regression.

In line 4,

Loaded a file in csv format named ‘file’ to make a list of independent and dependent values.

In lines 6 and 7,

Stored the list of independent values in variable called X and dependent values in variable called y.

In lines 9 and 10,

From sklearn module, import linear_model to use LinearRegression() method to create a linear regression object.

This object has a method called fit() that takes the independent and dependent values as parameters and fills the regression object with data that describes the relationship:

In line 13,

Now we have a regression object that are ready to predict ID value based on Weight and Roll_No.

Coefficient

Coefficient is the value, defined the with the variable.

Example: 8x, where 8 is a coefficient and x is a variable.

Example: Find the coefficient values of the regression object.

				
					import pandas as pd
from sklearn import linear_model

file = pd.read_csv("file.csv")

X = file[["Weight", "Roll_No"]]
y = file["ID"]

regression_data = linear_model.LinearRegression()
regression_data.fit(X, y)

print(regression_data.coef_)

				
			
				
					Output - 

Weight - [8.87761264e-02] 
Roll_No - [7.26086069e-05]

				
			

As a result, it returned coefficient value for both “Weight” and “Roll_No.”

Example: Assumed the different values for variables Weight and Roll_No to predict ID of a student.

				
					import pandas as pd
from sklearn import linear_model

file_read = pd.read_csv('file.csv')      # file read

X = file_read[["Weight", "Roll_No"]]     # independent value
y = file_read["ID"]                      # dependent value

regression = linear_model.LinearRegression()
regression.fit(X, y)                     # create linear object

# predict the Weight of a student where the Roll_No is 1500, and the ID is 4500:
predictIDvalue = regression.predict([[1500, 4500]])
print(predictIDvalue)

				
			
				
					Output - 

[201.23626454]
				
			

In the final analysis, it returned predicted value of variable ‘ID.’

If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.

Connect on:

Recent Post

Popular Post

Top Articles

Archives
Categories

Share on