import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from sklearn import linear_model
df = pd.read_csv('data.csv')
df.head()
Out[11]:
Car Model Volume Weight CO2
0 Toyoty Aygo 1000 790 929
1 Mitsubishi Space Star 1200 1160 95
2 Skoda Citigo 1000 929 95
3 Fiat 500 900 865 90
4 Mini Cooper 1500 1140 105
In [9]: [|
X = df[[ 'Weight', 'Volume']]
y = df['C02"]
In [12]: |
regr = linear_model.LinearRegression()
regr.fit(X, y)
out[12]:
LinearRegression()
#predict the C02 emission of a car where the weight is 2306kg, and the volume is 1300cm3
predictedC02 = regr.predict([[2300, 1300]])
print (predictedC02)
[107.2087328]