Page 155 - Data Science Algorithms in a Week
P. 155
Regression
Input:
We use the data from the table in example weight prediction from height and save it in a
CSV file.
# source_code/6/height_weight.csv
height,weight
180,75
174,71
184,83
168,63
178,70
172,?
Output:
$ python regression.py height_weight.csv
Linear model:
(p0,p1)=[0.9966468959362077, 0.4096393414704317]
Unknowns based on the linear model:
('172', 71.45461362885045)
The output for the linear model means that the weight can be expressed in terms of the
height as follows:
weight = 0.4096393414704317 * height + 0.9966468959362077
Therefore, a man with a height of 172cm is predicted to weigh 0.4096393414704317 * 172 +
0.9966468959362077 = 71.45461362885045 ~ 71.455kg.
Note that this prediction of 71.455kg is slightly different from the prediction in R of
67.016kg. This may be due to the fact that the Python algorithm found only a local
minimum in the prediction or that R uses a different algorithm or its implementation.
[ 143 ]