Friday, January 3, 2014

What is the equation for my weight?

I’ve been actively running since early September. I much prefer riding a bicycle, especially to work, which used to be 9.5 miles either way. Unfortunately a bicycle is a poor transportation choice for toddlers.

Accordingly, I’ve lost quite a bit of weight. 20 pounds in 4 months, which isn’t too shabby. The rate of loss seems to have slowed, so I decided to figure out what equation is the best fit for my weight.

Naturally, there’s a way to do this in Python, and it’s pretty easy.

from numpy import polyfit

x = [<a whole bunch of integers representing days since 9/1/13>]
y = [<a whole bunch of doubles representing weight>]

# this part is interactive:

>>> polyfit(x,y,2)
array([  5.36576978e-04,  -2.05927136e-01,   2.30620968e+02])

Well. That was easy. So the equation approximating my weight is:

.000536x^2 -.205921 x + 230.62

Naturally, I wanted to know what I’d weigh in the future.

>>> (a, b, c) = polyfit(x,y,2)
# this seems... silly
>>> d = [c,b,a]
>>> Poly = numpy.polynomial.polynomial.polyval

Day 121 checks out, so things are good. What about the future?

>>> Poly(200, d)
210.89861954517085
>>> Poly(300,d)
217.13475489610073
>>> Poly(400,d)
234.10242981212033
>>> Poly(1000, d)
561.27081017512194

Uh oh. I didn’t plan on doubling my weight 3 years from now. Maybe my weight isn’t a 2nd degree polynomial with a positive coefficient.

What I’m looking for looks a lot more like 1/x. Which, if I recall, is by definition not a polynomial. The search continues…

1 comment:

  1. Nice job dude. You might want to try switching over to Pandas or scikit-learn if you'd like to a more advanced analysis :) Plus, pretty pictures!

    ReplyDelete