In [1]:
import pandas as pd
from sklearn import linear_model
import matplotlib.pyplot as plt
pandas will let us read the data.
scikit-learn is the machine learning library
matplotlib will let us visualize our model and data
In [2]:
# read data
dataframe = pd.read_fwf('brain_body.txt')
x_values = dataframe[['Brain']]
y_values = dataframe[['Body']]
In [3]:
body_reg = linear_model.LinearRegression()
body_reg.fit(x_values, y_values)
Out[3]:
In [4]:
plt.scatter(x_values, y_values)
plt.plot(x_values, body_reg.predict(x_values))
plt.show()