In the following code, a comparison has been made between applying linear regression in a statistical way and gradient descent in a machine learning way on the same dataset:
>>> import numpy as np >>> import pandas as pd
The following code describes reading data using a pandas DataFrame:
>>> train_data = pd.read_csv("mtcars.csv")
Converting DataFrame variables into NumPy arrays in order to process them in scikit learn packages, as scikit-learn is built on NumPy arrays itself, is shown next:
>>> X = np.array(train_data["hp"]) ; y = np.array(train_data["mpg"]) >>> X = X.reshape(32,1); y = y.reshape(32,1)
Importing linear regression from the scikit-learn package; this works on the least squares ...