mlr
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn import metrics
%matplotlib inline
dataset = pd.read_csv('Downloads/cars.csv')
print(dataset.shape)
print(dataset.head(5))
print(dataset.describe())
dataset.plot(x='Volume',y='Weight',style="*")
plt.title('Cars')
plt.xlabel('Volume')
plt.ylabel('Weight')
plt.show()
x = dataset[['Weight','Volume']]
y = dataset['CO2']
x_train,x_test,y_train,y_test = train_test_split(x,y,test_size=0.2,random_state=0)
MLR = LinearRegression()
MLR.fit(x_train,y_train)
print("Intercept = ",MLR.intercept_)
print("Coefficient = ",MLR.coef_)
predicatedCO2 = MLR.predict([[1500,1140]])
print(predicatedCO2)
predicatedCO2 = MLR.predict([[1200,1300]])
print(predicatedCO2)
error = abs(predicatedCO2-y_test)
print('MAE -',round(np.mean(error),2))
mape = (100*(error/y_test))
accuracy=(100-np.mean(mape))
print("accuracy = ",round(accuracy,2),'%')