VOOZH about

URL: https://www.geeksforgeeks.org/machine-learning/calories-burnt-prediction-using-machine-learning/

⇱ Calories Burnt Prediction using Machine Learning - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Calories Burnt Prediction using Machine Learning

Last Updated : 23 Jul, 2025

In this article, we will learn how to develop a machine learning model using Python which can predict the number of calories a person has burnt during a workout based on some biological measures.

Importing Libraries and Dataset

Python libraries make it easy for us to handle the data and perform typical and complex tasks with a single line of code.

  • Pandas- This library helps to load the data frame in a 2D array format and has multiple functions to perform analysis tasks in one go.
  • Numpy - Numpy arrays are very fast and can perform large computations in a very short time.
  • Matplotlib/Seaborn - This library is used to draw visualizations.
  • Sklearn - This module contains multiple libraries are having pre-implemented functions to perform tasks from data preprocessing to model development and evaluation.
  • XGBoost - This contains the eXtreme Gradient Boosting machine learning algorithm which is one of the algorithms which helps us to achieve high accuracy on predictions.

Refer to the links given below for the dataset used in the article:

To proceed with the model, you need to merge both the datasets. Refer to link below to see how to merge two datasets.

How to join datasets with same columns and select one using Pandas?

Now let's load the dataset into the panda's data frame and print its first five rows.

Output:

👁 First five rows of the dataset
First five rows of the dataset

Now let's check the size of the dataset.

Output:

(15000, 9)

Let's check which column of the dataset contains which type of data.

Output:

👁 Information of the columns data type
Information of the column's data type

Now we will check the descriptive statistical measures of the data.

Output:

👁 Descriptive statistical measures of the dataset
Descriptive statistical measures of the dataset

Exploratory Data Analysis

EDA is an approach to analyzing the data using visual techniques. It is used to discover trends, and patterns, or to check assumptions with the help of statistical summaries and graphical representations. 

Output:

👁 Scatterplot of height v/s weight
Scatterplot of height v/s weight

So, we have a kind of linear relationship between these two features which is quite obvious.

Output:

👁 Scatter plot for features and target column
Scatter plot for features and target column

As expected higher is the duration of the workout higher will be the calories burnt. But except for that, we cannot observe any such relation between calories burnt and height or weight features.

Here we can observe some real-life observations:

  • The average height of the boys is higher than girls.
  • Also, the weight of the girls is lower than that of the boys.
  • For the same average duration of workout calories burnt by men is higher than that of women.

Output:

👁 Distribution plot for continuous features
Distribution plot for continuous features

The distribution of the continuous features follows close to normal distribution except for some features like Body_Temp and Calories.

Output:

👁 First five rows of the dataset
First five rows of the dataset

Output:

👁 Heatmap to detect highly correlated features
Heatmap to detect highly correlated features

Here we have a serious problem of data leakage as there is a feature that is highly correlated with the target column which is calories.

Model Training

Now we will separate the features and target variables and split them into training and testing data by using which we will select the model which is performing best on the validation data.

Output:

((13500, 5), (1500, 5))

Now, let's normalize the data to obtain stable and fast training.

Now let's train some state-of-the-art machine learning models and compare them which fit better with our data.

Output:

LinearRegression() : 
Training Error : 17.893463692619434
Validation Error : 18.007896272831253

XGBRegressor(base_score=None, booster=None, callbacks=None,
 colsample_bylevel=None, colsample_bynode=None,
 colsample_bytree=None, device=None, early_stopping_rounds=None,
 enable_categorical=False, eval_metric=None, feature_types=None,
 gamma=None, grow_policy=None, importance_type=None,
 interaction_constraints=None, learning_rate=None, max_bin=None,
 max_cat_threshold=None, max_cat_to_onehot=None,
 max_delta_step=None, max_depth=None, max_leaves=None,
 min_child_weight=None, missing=nan, monotone_constraints=None,
 multi_strategy=None, n_estimators=None, n_jobs=None,
 num_parallel_tree=None, random_state=None, ...) : 
Training Error : 7.89463304294701
Validation Error : 10.12050432946533

Lasso() : 
Training Error : 17.915089584958036
Validation Error : 17.995033362288662

RandomForestRegressor() : 
Training Error : 3.9877936746031746
Validation Error : 10.451300301587302

Ridge() : 
Training Error : 17.893530494767777
Validation Error : 18.00781790803129

Out of all the above models, we have trained RandomForestRegressor and the XGB model's performance is the same as their MAE for the validation data is same.

Get the Complete notebook:

Notebook: click here.

Dataset: click here.

Comment
Article Tags: