Using Amazon Machine Learning to Predict the Best Time of Day for Exercise – Pt 2: The Learning Model

Amazon Machine Learning, leveraging activity data from a your Fitbit, can be used to predict workout intensity.

MachineLearning_VideoThumbnail[1][su_note note_color=”#d3d3d3″]Note: This is the second post about using Amazon Machine Learning to predict workout intensity. Check out Part 1 (Overview) for background. A third post will cover the Lambda and Alexa code used to automate the model. A working model is available via web and Alexa. Code can be found/downloaded from my Hackster site.[/su_note]

When creating my prediction model, I first had to define workout effectiveness. Was it measured by the total number of minutes that I worked out, or my average heart rate? Should I consider my peak heart rate, or number of calories burned.

After doing some research, I decided that workout intensity would be best captured my the number of “active minutes” for each workout. From the Fitbit website:

All Fitbit trackers calculate active minutes using metabolic equivalents (METs). METs help measure the energy expenditure of various activities. Because they do so in a comparable way among persons of different weights, METs are widely used as indicators for exercise intensity. For example, a MET of 1 indicates a body at rest. Fitbit trackers estimate your MET value in any given minute by calculating the intensity of your activity.

From there, I needed to determine what inputs impacted workout intensity. After more reading, I landed on the following as inputs to a successful workout.

  • Sleep (or lack of sleep)
  • Previous Day’s activities
  • Time of Day
  • Stress
  • Food Intake60700774[1]

My Fitbit tracks sleep and the amount of total activity of a given day (measured with the count of total active calories burned in a day). I can also get the start time of each workout and the resultant active minutes in that workout.

Stress, being subjective, is harder to measure. I originally used the number of meetings in my outlook calendar to determine my level of stress, but found that metric to be inaccurate (at least, without additional research/tuning).

Finally, while I track food intake, not everyone does. Plus, the best food indicator for a good workout is the amount and type of calories consumed 2-3 hours before a workout. I didn’t think the food input tracking tools were accurate enough to input this into the model, so I ignored it.

Amazon Web Services has a Machine Learning service that I thought could be used to predict workout intensity. I extracted 4 months of workout data to build and train a model to predict workout intensity1.

The inputs:

  • Type of Activity (weights, yoga, cycling, etc.)2
  • Day of the Week
  • Time of Day (Morning, Mid-Day, Afternoon, Evening)
  • Active Calories Burned the Previous Day
  • Number of minutes sleep (for the previous night)
  • Weight

Then, I needed to decide on the correct prediction model. Amazon Machine Learning has three options:

  • Binary classification (yes/no, 1 or 0)
  • Multi-class classification (categorical attributes – for example – Morning, Mid-Day, Afternoon)
  • Regression  (numeric attributes – for example – Number of active minutes)

Binary classification wasn’t an option for my model. I considered using multi-class, but decided against it. I ultimately went with a Regression Model, where the predicted output value was the number of active minutes.

My first models weren’t very good – I either had too much data (when I included the calendar information) or my data wasn’t complete (I didn’t have sleep minutes on certain workout days because I forgot to wear my Fitbit to bed)3.

After building 5 or 6 models, I ultimately came up with a prediction model that returned results better than the baseline.

Model PerformanceIn order to find the best time of day, I passed the same day, sleep, weight, and calorie variables – only changing the time of day. The highest predicted value would indicate the best time to go to the gym. As seen in the screen shots below, based on the same inputs, I’ll most likely have the most intense workout between 11AM – 2PM (Mid-Day).

 

Afternoon Mid-Day Evening Morning

Next Post – Automating the Model build and tying it to Alexa.

Footnotes

  1. I used the APIs exposed by Fitbit to retrieve this data, which I the formatted, saved to S3, and used to create the machine learning data source.
  2. I excluded ‘Walking’ from my data set; I felt that those metrics would throw the model off.
  3. I got around this problem by assuming that the user slept for 6 hours if there was no saved sleep minutes value.

Leave a Reply