Predicting Steps from Wearable activity tracking device

Avatar
Posted on Mar 3, 2016

I. Introduction

Nowadays, there are wide selections and different price options for wearable activity tracking devices, or “wearables”. Most of these tracking devices harness a 3-axis accelerometer to understand the user’s motions. By analyzing acceleration data, the trackers provide information about frequency, duration, intensity, and patterns of movement to determine a multitude of health metrics, such as steps taken, distance traveled, calories burned, and sleep quality. Another advantage of owning this device for data and fitness enthusiasts is the ability to log their food, activities, and weight over time with the possibility to set daily and weekly goals for themselves for steps, calories burned and distance walked. One of the most popular wearable tracking devices is Fitbit. Like most wearable activity tracking devices,  there is the option to synchronize your data to your user account via Fitbit Connect. In this work, we consider Steps as our health and fitness goal that we wish to predict.

II. The Data

Fitbit users can extract their data by logging into their Fitbit Connect account as shown in Fig.1 below, where data for one year of activities and sleep could be extracted in CSV format.

dummy_export_upd

Fig. 1 : Data Extraction for Fitbit user’s webpage

After gathering a one year activities and sleep data, an exploratory data analysis is achieved using Python in order to determine the assess the relationship or determine the patterns between different type of measurements from May 8 2015 to May 7 2016. For each day, the extracted data has the following features (columns of our datasets):

  • Calorie burned
  • Steps
  • Distance
  • Floors
  • Minutes Sedentary
  • Minutes Lightly Active
  • Minutes Fairly Active
  • Minutes Very Active
  • Activity Calories
  • Minutes of Sleep
  • Minutes of Being Awake
  • Number of Awakenings
  • Length Of Rest In Minutes

III. Exploratory data analysis

First we take a look to the distribution of our raw data as shown in Fig.2 below.

2 3 capstone_nyc-ipynb

Fig. 2 : Raw Data

Based on the raw data from Fig.2, we can see the following:

  • There are no missing values in the dataset
  • Some of the data are zero, this is because Fitbit is not worn, is charging or due to some failures in synchronizing the data
  • Sedentary minutes are longer than activity minutes
  • Light activity has a distribution that resembles the gaussian distribution
  • There are less minutes fairly active or very active days. Distribution appear as a log normal distribution
  • Floors feature describes elevation or climbing and seems to have a log normal distribution
  • On average Sleep is around 5 to 6 hours
  • Daily Steps vary between 5000 and 20000 steps equivalent to a distance up to 12 miles

In this dataset, we distinguish 3 types of health or fitness goals: Steps, Calories burned, Hours of Sleep, and Sleep efficiency. To assess the sleep quality for a specific day, we define Sleep efficiency as the percentage of Minutes of Sleep over Length Of Rest In Minutes.

In the following section, these goals are represented over days of the week, months and grouped by work days (from Monday to Friday) and weekends (Saturday and Sunday).

  1- Goals observations

        1.a - variations by days of the week

Most of the global recommendations on physical activity for health are targeted toward meeting certain daily goals. Fig.3 below shows the daily achieved goals.

steps_days1 steps_days2

Fig. 3 : Daily goals

  • On average, the Fitbit user achieve between 8500 to nearly 12000 steps by day. According to Fitbit, the daily recommended steps for an adult are 10000 steps, which is equivalent to 30 min of daily exercise. Saturday is the most active day.
  • On average, the Fitbit user sleep between 5-6 hours and sleep the longest on Thursday. This is below the recommended by The Journal of the National Sleep Foundation. For an adult it is between 7-9 hours
  • The sleep efficiency seems constant around 85% and is also considered by The Journal of the National Sleep Foundation as a normal sleep cycle.
  • Calories burned are around 3000  which is more than the average person According to World Health Organisation, is between 1,600 and 2,000 calories per day.

            1.b- Goals parameters- variations by months

Although there are no global recommendations on physical activity for health, it is interesting to observe the evolution of goals parameters by month. We can see that October was the least active month, with few hours of sleep despite having the highest sleep efficiency. From Fig.4, we can also observe that the Fitbit user is more active during Spring and Summer months with higher hours of sleep but low sleep efficiency.

steps_months steps_months2

Fig. 4 : Monthly goals

            1.c- Goals parameters- variations by workdays or weekend

A new feature is created to group days by workdays (from Monday to Friday) and Weekends (Saturday and Sunday). Fig.5 shows the achieved goals parameters. During the workdays, the Fitbit users improve all the health goals comparing to weekends.

workdays_weekend1 workdays_weekend2

Fig. 5 : Workdays and Weekend goals

  2.Data interaction

In the following section, the relationship between several features in the dataset is observed. Along with the feature that distinguishes between workdays and weekends, other features are added to the datasets such as: Yesterday sleep hours and Yesterday's sleep efficiency in order to assess the effects of a previous night sleep on the goals. The following features: Days, Months and Weekdays have been encoded.

In this work, we consider Steps as our health and fitness goal that we wish to predict.

            2.a - Correlation

First, we look at the trend shared by predictors, i.e the features that will be used to predict Steps. We compute the correlation matrix shown in Fig.6.

correlation

Fig. 6 : Correlation matrix

From Fig.6, we can observe some strong correlation between some sleep predictors.  Distance is strongly correlated to Floors and both are inter-correlated to Minutes very active.

   3- Data analysis insights

  • In order to build our steps prediction model, we choose only to keep the variables Hours Sleep and Yesterday Sleep which respectively describe the sleep quality for the same day and day before.
  • Our data shows some strong correlation between predictors such as Distance and Minutes very active (0.76 correlation).  If two predictors are strongly correlated (correlation coefficient>0.76 ) we choose to keep only one in order to avoid redundant information in our data.

Fig.8 shows the relationship between Steps and other predictors. We can see that there is a strong linear relationship between Steps and the predictors. Distance according to Fitbit is calculated by multiplying your walking steps by your walking stride length.

Steps_distance_floors_calorie

Steps_date

Steps_activity

Fig. 8 : Relationship between Steps and predictors

II. Steps prediction and Evaluation

In order to predict the Steps, we split our data into train (75% of the dataset) and test (25% of the dataset). The train data has the following predictors:

  • Calories burned
  • Distance
  • Floors
  • Minutes Sedentary
  • Minutes Lightly Active
  • Minutes Fairly Active
  • Minutes Very Active
  • Activity Calories
  • Work_or_Weekend
  • Hours Sleep
  • Yesterday Sleep
  • Months encoded

We fit different machine learning algorithms on our train dataset and make corresponding predictions on our test dataset. First we assess variable importance using linear regression and test p values for each predictor. Results are shown in Table.I

table

Table I : Feature importance and p-value

In order to measure models accuracy, we compute the RMSE and R2 as shown in Table.II.

edit

Table II : Prediction Scores for different Machine Learning

From Table II, simple linear regression seems to be well suited for the nature of this prediction problem as it has a lower value of RMSE in this case we have an error of 3437.32 steps. No improvement is observed using regularization such as Lasso or Ridge.

Fig.9 shows the comparison between Predicted Steps and Steps from the test dataset.

models

Fig. 9 : Comparison between models- Predicted Steps and Test Steps

III. Discussion

Considering the nature of our data, we have some multicollinearity and also a strong linear relationship between some features and our response variable Steps. Multicollinearity is important in regression analysis as it may cause unstable estimated coefficients and a loss of the model interpretability as it depends on the data used to train our model. In order to have a constrained model, we introduce regularization of the linear regression using Ridge and Lasso methods to predict the Steps based predominantly on the most important features. Regularization, in this case, shrinks the least important coefficients (Ridge) or can eliminate them completely (Lasso) in order to improve generalization of the model. For this model, regularization doesn't improve interpretability or the predictive power of the model.

As for the Random Forest Regressor, it fails in predicting Steps especially for small values as observed in Fig.9. In the exploratory analysis, the mean daily Steps is between 8000 and 12000. The poor results of Random Forest Regressor are due to the nature of the algorithm being a nonlinear algorithm. In our case, our data is very linear and thus we need a lot of branches per tree to get a good approximation.

VI. Conclusion

In this work, the relationship between the measured Fitbit parameters was explored. We choose to predict the number of steps based on multiple features. Despite an apparent multicollinearity, simple linear regression seems to give better results predicting the number of steps.

 

About Author

Related Articles

Leave a Comment

Avatar
Bruce Clark November 28, 2017
Magnificent beat ! I would like to apprentice while you amend your site, how could i subscribe for a weblog site? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast provided vibrant clear concept

View Posts by Categories


Our Recent Popular Posts


View Posts by Tags

2019 airbnb alumni Alumni Interview Alumni Spotlight alumni story Alumnus API Application artist aws beautiful soup Best Bootcamp Best Data Science 2019 Best Data Science Bootcamp Big Data Book Launch Book-Signing bootcamp Bootcamp Prep Bundles California Cancer Research capstone Career Career Day citibike clustering Coding Course Demo Course Report D3.js data Data Analyst data science Data Science Academy Data Science Bootcamp Data Scientist Data Scientist Jobs data visualization Deep Learning Demo Day Discount dplyr employer networking feature engineering Finance Financial Data Science Flask gbm Get Hired ggplot2 googleVis Hadoop higgs boson Hiring hiring partner events Industry Experts Job Jon Krohn JP Morgan Chase Kaggle Kickstarter lasso regression Lead Data Scienctist Lead Data Scientist leaflet linear regression Logistic Regression machine learning Maps matplotlib Medical Research meetup Networking neural network Neural networks New Courses nlp NYC NYC Data Science nyc data science academy NYC Open Data NYCDSA NYCDSA Alumni Open Data painter pandas Part-time Portfolio Development prediction Prework Programming PwC python python machine learning python scrapy python web scraping python webscraping Python Workshop R R language R Programming R Shiny r studio R Visualization R Workshop R-bloggers random forest recommendation recommendation system regression Scrapy scrapy visualization seaborn Selenium sentiment analysis Shiny Shiny Dashboard Spark Special Special Summer Sports statistics streaming Student Interview Student Showcase SVM Tableau TensorFlow Testimonial tf-idf Top Data Science Bootcamp twitter visualization web scraping Weekend Course What to expect word cloud word2vec XGBoost yelp