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 the pandas library using the statement import pandas as pd.
Import the linear_model module from scikit-learn using the statement from sklearn import linear_model.
Read the CSV file named "cars.csv" using the pd.read_csv() function and store the data in a DataFrame named df.
Get the value of X and y variables and Create the linear regression model and fit.
Predict the CO2 emission using the trained linear regression model by calling the predict() method on regr [[3300, 1300]]
Print the Predicted CO2
#Developed by: JANARTHANAN V K
#RegisterNumber: 212222230051
import pandas as pd
from sklearn import linear_model
df=pd.read_csv("/content/cars.csv")
x=df[['Weight','Volume']]
y=df['CO2']
regr=linear_model.LinearRegression()
regr.fit(x,y)
print("Coefficient:",regr.coef_)
print("Intercept:",regr.intercept_)
predictedCO2=regr.predict([[3300,1300]])
print("Predicted CO@ for the corressponding weight and volume",predictedCO2)
Thus the multivariate linear regression is implemented and predicted the output using python program.