Page 152 - Data Science Algorithms in a Week
P. 152
Regression
Output:
$ Rscript weight_prediction.r
Call:
lm(formula = weight ~ height, data = men)
Coefficients: (Intercept) height
-127.688 1.132
Thus the formula expressing the linear relationship between the weight and the height is as
follows: weight=1.132*height-127.688. Therefore, we estimate that the man with the height of
172cm would have the weight 1.132*172-127.688=67.016 kg.
Gradient descent algorithm and its
implementation
To understand better how we may be able to predict a value using linear regression from
first principles, we study a gradient descent algorithm and then implement it in Python.
Gradient descent algorithm
A gradient descent algorithm is an iterative algorithm updating the variables in the model
to fit the data with the least error. More generally, it finds a minimum of a function.
We would like to express the weight in terms of the height using a linear formula:
weight(height,p)=p 1 *height+p 0
We estimate the parameter p=(p0,p ) using n data samples (height ,weight ) to minimize the
i
i
1
following square error:
[ 140 ]