First Neural Networks

We have a dataset of measurement of different animals of brain weight and body weight. We want to predict an animal's body weight given its brain weight.

Since our data is labeled this will be Supervised approach and type of machine learning task is called Regression.


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

Read the Data


In [2]:
# read data
dataframe = pd.read_fwf('brain_body.txt')
x_values = dataframe[['Brain']]
y_values = dataframe[['Body']]

Train model on the Data


In [3]:
body_reg = linear_model.LinearRegression()
body_reg.fit(x_values, y_values)


Out[3]:
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)

Visualize results


In [4]:
plt.scatter(x_values, y_values)
plt.plot(x_values, body_reg.predict(x_values))
plt.show()