✅ Join the DemystifAI newsletter! ✅


Weight-management With Data Science - Debugging Life #002



Two robots showing their postures
Image created with DALL·E 3


Imagine you want to lose, maintain or gain weight. It’s a tricky issue and a true challenge nowadays. Planned weight management requires discipline and sticking to a plan. This is no walk in the park.

I’ll skip discussing the health hazards correlated with improper weight levels (either weighing too much or too little). Just imagine you want to change something. Imagine.

I have quite a journey with weight management myself. I am no stranger to sports but also no stranger to binge-eating or binge-whatevering (Hey Netflix and Papa Johns, if you want to sponsor me - you still have a chance).

I am 1.83 cm tall (6 feet).
I weighed around 77 kg (~170 lbs) in October 2017.
I weighed around 102 kg (~225 lbs) in May 2019 (great times).
I weighed around 80 kg (~176 lbs) in March 2021.
I weighed around 89 kg (~196 lbs) in December 2021.
I weighed around 75 kg (~175 lbs) in October 2022.
I’m weighing around 86 kg (~190 lbs) now - June 2024.

My picture in 2019 weighing 92+kg vs my picture in 2022 weighing 80kg
From my personal archives. On the left - beautiful Georgian (the country) mountains in September 2019 weighing 92+kg (~203+ lbs). On the right - beautiful Warsaw suburbs weighing around 80kg (~176 lbs).


As you can see, I love rollercoasters.

My goal now is to go down to around 81 kg and stick around - reduce weight deviation in the long run.

Now, taking into consideration that I am a bit of an analytics nerd, how could I approach achieving this task? Let’s put the sweet science of data into practice.

The beauty of it? Think of it as a personal project. But the same principles would be applicable to a commercial project.

Obviously, this will only scratch the surface of this challenge. However, having more tools to tackle this problem will allow you to deep dive and expand the strategy on your own.

1. Specify Your Goal


A common framework for that, albeit in a new shape, is the SMARTER method, where it stands for:

  • S - specific (I want to achieve X kg / lbs).
  • M - meaningful (make it personal; make it a priority. Remember - it’s one priority, not ten priorities.).
  • A - achievable (a weight of 0 kg or 667 kg might be out of reach - although I am not 100% sure about the latter).
  • R - relevant (in line with other goals; the goal of decreasing weight might not work if your other goal is to test different fast-food chains every day).
  • T - time-bound (I want to achieve this goal by D-date).
  • E - evaluate (I’m going to evaluate frequently if I am moving in the right direction).
  • R - re-adjust (I’ll recognize what’s working and what’s not working and adjust my actions based on that).

So let’s assume that the current status is that I weigh 85 kg and I want to weigh 81 kg by the end of August. I’m going to evaluate by weighing myself every Monday morning after I wake up.

I’m going to keep a journal of what I am doing on particular days, compare it with the results of the evaluation, and based on that, re-adjust my actions.

What exactly should I do? What metrics should I track?

2. Obtain Domain Knowledge


I know what I want to do. Now I need to know how to do it best.

When obtaining domain knowledge, it is crucial to refer to high-quality sources. These can include scientific research (preferably meta-analyses) or established experts with a proven record.

You can use great tools like Perplexity.ai for your “discovery phase.” As always, double-check answers and sources.

2.1 Foundation Model


We will start with the First Law of Thermodynamics (gotta love your physics classes from school, don’t ya?).


1st Law of Thermodynamics equation
Image created with Excalidraw


where:
∆U - change in system’s internal energy,
Q - heat supplied to the system,
W - heat expended by works of the system.

Ok, that’s cool - but why do I care?

Because, at a very high, simplified level, this applies to our body weight as well (see: “A Mathematical Model Of Weight Change With Adaptation” ):


Mathematical model for rate of stored kcal
Image created with Excalidraw


where:
R - rate of stored kcal (kilocalories; 1kcal = 1000 calories) change,
I - rate of kcal intake,
E - rate of kcal expended.

Now, this equation can be further expanded, and the relationship is not linear. It’s not even the same for everybody (there can be genetic differences affecting your pace of weight change; see “Genetics of Exercise and Diet-Induced Fat Loss Efficiency: A Systematic Review”).

But for the case of my goal, let’s try to keep it simple. At the basic level, we need to monitor:

  • my body weight (goal; target variable).
  • my calorie intake (how much I eat; explanatory variable).
  • my calorie expenditure (tricky to assess exact figure, usually simplified by counting how much exercise one has; explanatory variable).

Based on observed changes in my target variable, I will try to adjust the values of my explanatory variables (easier said than done).

2.2 Best Practices


Ok, so you want to manage your weight level. I assume you want to do it right, because you’re simply the best!

So - you do further research and get some additional advice on how to tackle your problem optimally (good idea to use Perplexity.ai here as well).

Some general advice will be:

  1. Follow a Mediterranean-style diet for optimal cardiovascular benefits (macronutrient composition: 50-60% carbs, 15-20% protein, 30% fats). See: “Diet quality and cardiovascular outcomes: A systematic review and meta-analysis of cohort studies”.
  2. Exercise regularly (let’s assume 2-3 training sessions per week). See: “Healthy strategies for successful weight loss and weight maintenance: a systematic review”.
  3. Sleep 7-9 hours per day. See: “Sleep Deprivation: Effects on Weight Loss and Weight Loss Maintenance” .
  4. Limit ultra-processed foods because of their negative impact on your metabolic and mental health. See: “Ultra-Processed Food Exposure and Adverse Health Outcomes: An Umbrella Review of Epidemiological Meta-Analyses” .

And probably I could find out a lot more. You might want to tweak some of the advice or follow a different diet - however, do your research and if possible, consult an expert nutritionist.

If you already have a lot of knowledge on this topic, you will develop a certain intuition that will help you navigate through the ocean of choices to achieve the optimal outcome.

If you don’t have the knowledge, don’t trust your intuition! You might be fooled by “popular beliefs” and “pop science.”

Abraham Lincoln (guy who invented tall hats) once said:

“Give me six hours to chop down a tree and I will spend the first four sharpening the axe.”

Do your preparation properly.

3. Collect Data


We know what we want to do. Now we need to establish a basic data science methodology for data acquisition.

Rules (generic):

  1. Compare apples to apples: For example, when you weigh yourself, use the same scale and weigh yourself on the same day of the week and at the same hour each time (let’s say the first thing you do after getting out of bed on Monday is weighing yourself). That way, changes will be comparable over weeks. If you measure steps every day, use the same measurement tool. Switching from one tool to another may affect the measurements significantly. Important: it’s not recommended to weigh yourself every day. This increases the risk of developing unhealthy eating habits. Here’s what Perplexity found about it.

  2. Try to be as accurate as possible (but be reasonable). Use a kitchen scale to weigh your food ingredients. Use apps like Fitatu to count your calorie intake. If you eat out, try to eat in places where they have kcal information available. If there is nothing available, find something similar in Fitatu and add 100-200 kcal to it. Perfection is unattainable. For exercise and sleep, you can use tools like Oura Ring, Whoop, or Garmin. Alternatively, you can just relax and assess by yourself how much you slept and note down what training you did each day. Again, better done than perfect.

  3. Forgive yourself for any mistakes. Everyday is day 1. Remember the goal: 1% better each day. Don’t expect to be perfect. The best systems are those that are maintainable over long periods of time. If you slipped today, start over with a clean slate tomorrow.

So a simple daily observation for your explanatory variables could be something like:

  • Date - date of sample collection.
  • Kcal - kcal intake (how much did you eat?).
  • Training - did you train on that day? If you have more advanced tools, you could change this to total kcal expenditure on that day.
  • Sleep - did you sleep over 7 hours that day?
  • Junk_food - did you eat more than 20% of your calories from ultra-processed foods that day?

On top of that, every 7 days, you will measure your body weight.

The most crucial thing is to be honest with yourself (you can lie to others more if you need to maintain a certain balance 😉). If you ate more than planned on a particular day, assess how much and write it down as accurately as possible. Nobody will shout at you. You are doing this for yourself.

Also: avoid extreme approaches. It’s about developing healthy habits and long-term maintenance. For everything, there is a price to pay. And for doing things the extreme way, the price to pay might be steep.

4. Train and Test Sample


Usually, you would have cohort data, allowing us to observe how different conditions affect a particular variable. That’s why scientists conduct observational studies spanning across years and thousands of subjects, to find patterns that will likely have similar effects on “average” people (of course, nobody is “average,” champ 😉).

In a large sample for tabular data, I would split our sample (total of observations) into a set of training observations (on which we will train our model) and test observations (on which I would assess our model’s quality).

In the case of this project, the sample size is 1, and previous observations (what you did on past days) will affect today’s outcomes.

And that’s ok - we will focus on the long-term trend of our weight. Let’s look at this as a time series analysis problem or a single-subject clinical trial (is the treatment effect statistically significant?) Is it moving in the right direction?

The training sample is every past day that I collected data. I can observe what I did, and if I gather it together with weight measurements, I can get more or less an idea of how my actions impacted my weight level (with some unavoidable, but acceptable degree of error).

The test sample - I have only today to test my new assumptions (e.g., limiting calorie intake). I can follow a new strategy for a couple of weeks (ideally) and then check if the weight trend was positively affected by the tested “treatment.”

It is crucial to note if I actually followed treatment rules. If my assumption was to eat 2500 kcal per day, and for the first 7 days of the testing period I ate over 3000 kcal per day, then I haven’t really tested my assumption, have I?

5. Feature Engineering


When analyzing data, I often end up identifying new features (explanatory variables) that help me discover more patterns and better model the target variable. I will use a similar approach here.

My advice is to start small, but managing weight will become trickier as you start approaching your goal. Your body adapts, so your tactics may have to adapt as well.

That’s why you might need to assess need for introducing new features, like:

  • 8 000+ steps on non-training days.
  • Eating 500 grams of vegetables / day.
  • Avoiding processed sweets.

This will introduce new measured variables to your data collection system and provide additional information to determine if changes in tactics bring the desired outcomes.

6. Decide on Model / Treatment


I have decided what data I want to collect and have the knowledge to achieve my goal. Now it’s time to decide on the particular treatment.

For that, it’s best to observe my caloric “zero” – i.e., a state of steadiness for my weight. This means that over a particular two-week period, I observe no significant weight changes.

My recommendation is to monitor yourself closely for two weeks. If you lose weight, you’re eating too little (and if your goal is to lose weight, keep at it!). If you gain weight, you’re eating too much. If your weight is stable, then you know your level of calorie intake to maintain your current weight (if your lifestyle stays more or less the same).

Let’s assume I weigh 86kg and my stable weight is maintained when I intake 2500 kcal per day. If I want to lose weight, I can start by deducting 300 kcal per day and then observe what happens over the next two weeks.

After a period of two weeks (allow yourself enough time to test your strategy), I will observe how my tactic works in real life.

7. Monitor Performance on Production


Weight changed in the desired direction? Great.

Weight didn’t go where I wanted it to? I can either further change calorie intake or manipulate calorie expenditure by modifying my exercise regimen. Use feature engineering as well.

That’s the “evaluate” and “re-adjust” in practice. Observe your weight. Not satisfied? Increase the treatment level. Satisfied? Keep doing what you are doing until it stops working. Easy peasy lemon squeezy.

But be careful. Make changes in moderation. If your weight stalled for two weeks, and you added 5 training sessions while deducting 1000 kcal from your daily intake, that’s a recipe for fast burnout. Be smart and don’t believe in miracles.

If you analyze your data over a couple of weeks, you might notice very interesting things.

My key findings:

  1. Alcohol has calories (Whoaaa, what what?! One 25ml shot of vodka has around 60 kcal).
  2. It doesn’t matter if you consume excess calories from Kobe Wagyu beef or regular McDonald’s cheeseburgers - you’ll gain weight when you eat too much.
  3. It’s difficult to gain weight at a reasonable pace with good quality food. Counting your calories plays a crucial role here as well. You can gain weight easily on a fast-food diet, but your body and mind will both pay a high price.
  4. If you don’t report calories but eat them, it still counts. Somehow, your body knows better.
  5. Good rest matters. On numerous occasions, keeping the same calorie intake but starting to put an emphasis on 7 hours of sleep (so more than 8 hours in bed) moved the needle for me.
  6. Stress and travel can cause temporary weight gain due to increased water retention.
  7. Vacations and trips should not be “all you can eat” festivals if you want to maintain a healthy weight level.

Below are my weekly weight (in kg; red line) and waistline (in cm; blue line) measurements (1 cm under the belly button; you can measure it differently as long as it is measured the same way every week) for the last couple of years.

Weight and waistline measurements graph from May 2020 to June 2024
Screenshot from my secret Excel file


You can see some weeks when I didn’t do any measurements. Well, I am not perfect, but I keep getting better.

I started to do frequent measurements and develop healthier habits around May 2020 when I began working with a professional nutritionist and strength & conditioning coach, Łukasz Stelmaszczyk whose services I can sincerely recommend (give his YT channel a subscription - unfortunately it’s only in Polish YET). Most of the time it’s better to work with a mentor/expert (use domain knowledge) instead of learning everything by yourself.

Recently, I started a reduction phase, and my weight is constantly around 86kg (~190 lbs). Last week, I cut calories, but my weight still stands still. I’ll be more precise with my measurements this week (I admit honestly - I might have had a bite here and there without reporting it in Fitatu). I’ll keep the same level of activity and see if the weight moves. If not, I’ll have to cut more calories and/or add one training session per week. Then, I’ll conduct a two-week test and go back to the drawing board.

I’m curious, if you went through a similar project in your life: what were your surprising findings?

8. Systemize and Automate


Do your analysis right, observe yourself, and you will become a better subject matter expert: a subject matter expert on yourself.

You might end up designing decision trees for your life. Some basic rules that you might come up with are:

  • Don’t order more than one meal at once. Decide if you want to order a second meal only after finishing the first one.
  • If you break your diet rules today, follow them exactly tomorrow.
  • Eat greens with every meal.
  • If you’re hungry and low on calories, eat low-calorie density foods like strawberries or potatoes.
  • Even if you are not working towards any weight goal now, keep weighing yourself once a week.
  • Book a constant time slot each week to go through collected data, analyze, and draw conclusions.

James Clear said:

“You do not rise to the level of your goals. You fall to the level of your systems.”

Hopefully, with everything I mentioned earlier, you will achieve some success in whatever you are planning.

If you do, build on it. Customize the framework to your needs.


9. Adapt to Other Parts of Your Life


You have a problem that needs fixing, and you don’t know what to do? Adapt this framework and use it to tackle the problem.

Not sure if that’s the correct attribution, but Karl Pearson (19th-century mathematician) supposedly said:

“That which is measured improves. That which is measured and reported improves exponentially.”

And I agree with that.

Improvise, measure, report, analyze, adapt, overcome.

Behind closed doors


Robot deeply thinking about something
Image created with DALL·E 3


Projects


E-book is finished!

I still have to figure out a way to distribute it (but don’t worry - it will come to my subscribers over the next couple of weeks for sure).

Trying to put it on Amazon KDP was a failed attempt - it expects a .txt file or Word document. My e-book is written in LaTeX, and I can’t be bothered with redoing it to a .txt format now.

I also tried a little bit of Calibre and tex4ebook to convert the e-book from .tex to EPUB or MOBI.

Generally, the pictures are getting all out of size and proportion. Some features, like directory trees, do not convert to text format without hassle.

To sum it up, my trials to prepare EPUB or MOBI versions failed miserably so far. I think I’ll stick to PDF format for now and see what the future brings. If there is demand, I’ll put more emphasis on non-PDF formats🤖.


Learnings


Continuing from last week’s learnings from Shane Parrish’s great book “Clear Thinking.”

Last week, I discussed falling into “default” ways of thinking.

This time, let’s see what values I can nurture to prevent this type of fallacy.

And the winners are:

  1. Self-accountability - taking ownership (accepting the world as it is and focusing on influencing what you can).
  2. Self-knowledge - using what you know about yourself to work for your benefit (“To know thyself is the beginning of wisdom” - Socrates. If you know you are a morning person, don’t leave the most important tasks for the end of the day!).
  3. Self-control - managing your reactions (like any skill, you get better with training. I said 3 cookies per day, not cookie jars!).
  4. Self-confidence - believing in yourself (be bold and daring enough to make mistakes; be humble enough to know that they don’t define you, and you can grow from them).

Now, you will need practice. You might even plan a SMARTER way of getting better at each of these “self” traits.

This will definitely be worth it. Practice will help you stand and defend your values (revolt against the social default), use self-knowledge to project your environment in a way that will benefit achieving your goals, and combined self-confidence and self-accountability will aid you in the constant process of improving the quality of your work and your standards.

Give it a try!

And that’s it for this weeks edition! See you on DemystifAI!

Any comments, remarks, questions - feel free to contact me at tomasz@demystifAI.blog. You can also leave any feedback anynomously here.

✅ Join the DemystifAI newsletter! ✅


Used links list: