Multivariate Gradient Descent in Python
The program below learns a linear relationship between a three-dimensional input and an output.
It downloads and operates on a dataset from Helmut Spaeth, Mathematical Algorithms for Linear Regression, Academic Press, 1991, ISBN 0-12-656460-4.
The data concerns pasture rent structure and grass variety and includes 67 examples. The inputs are
- the rent per acre of arable land,
- the number of milk cows per square mile, and
- the difference between pasturage and arable land
The output is the rental price per acre for this variety of grass. The program
includes a loss
function as well as a function that calculates the partial
derivative of the loss with respect to a specified element of .
Note:
-
This program depends on the
numpy
library, which can generally be installed using the commandpip install numpy
. -
This program will generally take a few minutes to complete execution and output the best-fit vector.