1- Import your packages
In [1]:
import numpy as nb
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
2- Create your data
In [2]:
cigarettes = nb.array([[1], [30], [60]])
hours = nb.array([[7], [210], [420]])
plt.scatter(cigarettes, hours)
plt.show()
3- Modeling Data
In [3]:
model = LinearRegression()
model.fit(cigarettes, hours)
Out[3]:
In [4]:
model.predict(80)
Out[4]:
In [5]:
cigarettes_test = nb.linspace(1,80)
hours_pred = model.predict(cigarettes_test[:,None])
plt.scatter(cigarettes, hours)
plt.plot(cigarettes_test, hours_pred,'r')
plt.legend(['Predicted line','Observed data'])
plt.show()