Bruno Arine

Predicting Body Weight Changes With Neural Networks

During 2014, I logged my body weight and food intake for 7 months daily for vanity science. Even though the simple, one-variable model (CICO or “calories-in vs. calories-out”) works pretty well in most cases, I wondered how, if at all, macros played a role in the grand scheme of diets.

I instantiated the artificial neural network via Python’s scikit-neuralnetwork, which is a sklearn-Esque wrapper for the well-known Theano library. The network is composed of two layers of 30 sigmoid units each. The input features vector comprises carbs, fat, and protein intake, plus fibers (since there’s some evidence that fibers help weight loss). I trained the network with a fortnight average from the original data. This downsampling was necessary to mitigate some of the noise. My bodyweight fluctuates a lot due to water retention, mainly when I go berserk on carbs (I’m talking about a ± 3kg change in the course of a weekend binge).

Figure 1: Weight change as predicted by neural network

Figure 1: Weight change as predicted by neural network

As expected, the machine learning model performed better than the simpler model, though I haven’t expected such great improvement, given the small training set. Interestingly, a simple linear regression with the same input features performed just as badly as CICO. This suggests that perhaps counting calories isn’t as linear as expected.

Unfortunately, I had no means to estimate body fat by that time. It would be great to evaluate how macros would affect body composition instead of total body weight. The slightly larger deviation between actual and predicted data by the end of the graph is due to creatine, by the way.

TDEE estimation

Total daily energy expenditure (TDEE) was estimated empirically (notes on how I did this are in the backlog).

The CICO model is actually a one-variable linear regression (i.e. weekly_weight_change = theta0 + theta1 x weekly_calories_intake). So, my total energy expenditure (TEE) is given by theta0 (intercept), namely the necessary amount of energy to make my weight remain unchanged. Since my workout was essentially the same throughout the year, my TEE is not supposed to change as well (though we know this is not quite the case).

How confident I am of my calorie tracking?

Averaging the original data will reduce random errors to a certain extent. However, I probably underestimate what I eat by a factor of 20%, as everyone else does. I’m supposing here that my underestimation is actually a systematic error. Hence, this bias should be automatically accounted by both models (linear regression and neural network).

Either our body isn’t a very accurate machine, or we simply don’t understand it enough. In any case, we all agree that weight change may be different each day, even though we consume the exact same meals; one day you’ll lose 500 grams, the other day you may gain 600, and lose another 700 the day after. If you feed this noisy daily data to the model, it will miss the bigger picture for the small details and nothing will come out of it. I tried to minimize this effect by taking the average of daily intakes and daily weight changes from the previous 14 days. So, what I teach my neural network from time to time is something like this: “Hello! 14 days have passed, eh? Look, I calculated some averages here and if I eat 220g carbs, 55g fat, 90g protein, and 20g fibers, my weight change is going to be -0.1kg”.I repeat the process until the end of the data.

The prediction curve works slightly different. Now, for every day in my data frame, I shove that day’s numbers into the model and expect it to spit an estimated weight change as the output.