Least-squares lines with NumPy
In this section, we will learn how to fit a line to a dataset by using the normal equation as well as by using Python libraries. We will also find the parameter values (β) and use these values to predict the Y values for some X value of our choice.
The relationship between the variables (horsepower and weight) can be represented by the following mathematical formulation:
Y βo + β1 X
Our goal is to find the values for βo and β1. Here, horsepower is the dependent variable (Y) and weight is the independent variable (X).
Before beginning the coding part, make sure that the Python file that you are editing and auto_dataset.csv
are in the same folder. If not, make sure to include the path for the .csv
file location in the Python file so that it can be read and used for computations. Also, the packages used in the coding exercises (numpy
, pandas
, seaborn
, matplotlib.pyplot
, and sklearn
) should be installed to avoid...