Machine Learning - Multiple Regression

Multiple Regression

Multiple regression is like linear regression, but more than one independent value, meaning that we try to predict a value based on two or more variables.

In Python we have modules. Start by importing the Pandas module.

import pandas

The Pandas module allows us to read csv files and restore DataFrame object.

df = pandas.read_csv("cars.csv")

Then make a list of the independent values ​​and call this variable X.

Enter values ​​based on a variable called y.

X = df[['Weight', 'Volume']]]

y = df['CO2']

We will use other methods from the sklearn module, so we will need to import that module:

Example
import pandas
from sklearn import linear_model

df = pandas.read_csv("cars.csv")

X = df[['Weight', 'Volume']]
y = df['CO2']

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

#predict the CO2 emission of a car where the weight is 2300kg, and the volume is 1300cm3:
predictedCO2 = regr.predict([[2300, 1300]])

print(predictedCO2)

We have predicted that a 1.3-liter engine, weighing 2300 kg, will emit about 107 grams of CO2 per kilometer.