remix logo

Hacker Remix

Predicting Weight Loss with Machine Learning

11 points by arijo 5 days ago | 19 comments

jvanderbot 5 days ago

This is pretty much what I do, as well!

I've found the equations for metabolism and weight to be accessible enough that I can just plug in daily calories and weight and get a nice prediction once you run it through a curve fit. Nothing too sophisticated required.

https://jodavaho.io/tags/diet.html

That's not to say that ML doesn't help. I use LLMs for super simple calorie tracking.

jflessau 5 days ago

A calorie tracker app has been my tool of choice for the past few years, one that includes a catalog of food items, meals, and recipes.

The two most useful features are the barcode scanner (scanning is much easier than typing into a search bar) and the fact that it knows, for example, how much a slice of cheese from a scanned package weighs. Weighing the food is actually the most annoying part, at least for me.

It’s even trickier when you're having breakfast and need to weigh butter, etc., before and after to get the difference, to avoid prepping everything beforehand.

All that sounds annoying, and it is. But compared to exercise, it has been a great time investment for me. Weighing things and using this app takes about 5 minutes a day. It yields results I'm happy with and significantly reduces uncertainty.

When you're unsure if you can eat one more thing near the end of the day, you can just look it up. Otherwise, uncertainty, at least for me, leads to under-eating, causing more hunger the next day, or overeating, jeopardizing the goal.

The thought of using an LLM to analyze a picture is intriguing.

I tried laying out items from the fridge on a plate and asking an LLM what I could make from them. That worked surprisingly well. But I like your idea much better.

The question is how accurate that would be. But snapping one more picture and testing it for a few weeks sounds fun.

Thanks for the food for thought! :)

arijo 5 days ago

I actually do that frequently to comply with my ketogenic diet - take a photo of the macro nutrients quantities, calories from the nutrition facts table on the food package and use ChatGPT or some other LLM to calculate the estimated calories per portion.

You can then validate the data by tracking your lost calories (calculable from your lost weight - I do it each week) and compare with the predicted weight lost calculated from the vendor 's nutrition facts table.

Terr_ 4 days ago

I had great results with calorie tracking, and I think it's because it recruited some part of my brain that is rather frugal, viewing calorie numbers like money, where some expenditures aren't justifiable and others are getting a good deal.

arijo 5 days ago

I think most of the classical statistical methods for curve fitting happen to be some kind of variant of using least squares on a manually chosen parameterizable function - you'll have to chose between a linear, polynomial, exponential or some other moire complex forms.

The nice things of using a simple feedforward DNN is that it will automatically infer both the nonlinear function structure and parameters and for simple basic use cases like this that don't require a lot of training it works well and you can even validate the fit visually by looking at the graph output.

apwheele 5 days ago

I'm sorry but this model is wild and highly misleading. Based on one variable and 7 observations, days since you have started, you have fit a model with `2 + 128 + 64^2` parameters. It happens that a straight line is fine for this data, so it does OK approximating the two observations that are in the test split.

I was curious to see what would happen out of sample, I figured it would just be a straight line (and it is, despite the parameters being quite complex, print out `model.weights` to check them out!)

    outS = [[365],[400],[450],[500],[2*365],[3*365],[4*365]]
    outY = model.predict(scaler_X.transform(outS))
    outY = scaler_y.inverse_transform(outY)
Negative if you keep at it long enough.

arijo 5 days ago

I don't intend to use the model to predict more than a couple of weeks - the fact that it has no data to predict more than that is not that a big deal for this use case.

Not very important, but the weight loss curve usually decelerates with time and this pattern is not captured by a straight line either - as i say not a big deal, it just happens that by using a simple DNN model for a simple curve I don't have to spend time choosing the type of function I want the data to fit.

Also the model will improve as the number of measurements that are available increases.

Your comment does make sense, I just think for this use case and short term prediction it's not a major problem.

I'd be happy to learn how you'd apply some renormalization techniques to reduce the number of parameters and prevent the overfitting - I'm just a noob very curious to learn as most as I can about practical deep learning techniques.

kcplate 4 days ago

> the weight loss curve usually decelerates with time and this pattern is not captured by a straight line either

I have done keto for weight loss across several stints, one lasting 4 years (I had a lot of weight to lose). I encountered plateaus at various points were despite pretty consistent caloric intake (at the time I religiously tracked everything), activity, and normal body eliminations, I would have periods of several weeks where my weight would not move at all, only to dramatically fall in a later week and continue the steady loss. I found it demotivating and had to adjust weigh ins from weekly to monthly to avoid the frustration.

I wonder what the model would say about those periods. I wish I would have kept the data from that time, it would have been interesting

arijo 4 days ago

Some ketogenic therapy experts theorize that a possible cause for those plateaus is due to the body reducing its metabolism due to what it thinks is an abnormal calorie deficit, entering survival mode - then after a period of adaptation it returns its metabolism to normal and the weight loss process continues.

I didn’t happen to find a plateau yet but surely will share the data if that happens.

mitjam 4 days ago

Thanks for sharing, I read all 4 parts and will definitely use this to improve my diet and activity (want to lose 10kg or about 12%). Looking forward for part 5.

jflessau 5 days ago

Would you mind elaborating on how you use LLMs to track calories?

Edit: nevermind, its all in the blog linked by you :)

arijo 5 days ago

Ha ha, no worries - I'm eager to learn from you guys as well :)

arijo 4 days ago

Spoken too early - I’ve skimmed the blog and it looked like a pretty thorough and likely more relevant analysis than this post.

sn9 4 days ago

ML and LLMs are complete overkill. You can do this with simple difference equations.

Anyway nowadays you can just use Macrofactor which makes it all easier (not just the calculations/predictions but the data input itself).

arijo 4 days ago

Thanks for the insight - I’ll do some research on that.

sn9 2 days ago

The key is that changes in bodyweight integrate all the relevant information, so if you're tracking bodyweight and calories, you have all the information you need to make actionable choices to manipulate your bodyweight at will.

Add in sufficient protein and strength training, and you can manipulate your body composition at will.

arijo 2 days ago

Thanks. Is that because one can get the basal rate from each weight plateau and then estimate the calorie deficit required to reach a certain weight target?

I guess the protein and strength training will make sure you keep your muscle mass while you are losing fat - is this correct?

sn9 1 day ago

The basal metabolic rate doesn't matter at all.

You want the Total Daily Energy Expenditure (TDEE) which is all the energy you use in a day. Tracking your calories and changes to your bodyweight lets you do that. (You'll want to use weekly averages of your bodyweight to smooth out fluctuations that don't reflect changes in tissue.)

Yes strength training with sufficient protein is a signal to your body to maintain or even build muscle mass, so every pound you lose will shift to mostly or entirely fat.

arijo 1 day ago

Thanks for the explanation: is there some book, blog, video, papers, or some other resoures where I can explore more on this subject?