To write a python program to implement multivariate linear regression and predict the output.
- Hardware – PCs
- Anaconda – Python 3.7 Installation / Moodle-Code Runner
Import panda
Import linear model from sklearn
Read the file cars.csv
Assign the values for x and y as required
Create the linearRegression model and predict the output
#DEVELOPED BY: NAVEEN S
#REG NO: 212222240070
import pandas as pd
from sklearn import linear_model
df =pd.read_csv("cars.csv")
x= df[["Weight","Volume"]]
y= df["CO2"]
regr =linear_model.LinearRegression()
regr.fit(x,y)
print("coefficients: ",regr.coef_)
print("Intercept: ",regr.intercept_)
predictedco2=regr.predict([[3000,1200]])
print("Predicted co2 for the coressponding weight and volume ",predictedco2)
Thus the multivariate linear regression is implemented and predicted the output using python program