image imagewidth (px) 522 2.41k |
|---|
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
Can we predict the calories burned during a workout based on physiological statistics, workout intensity, and lifestyle habits?
This dataset comes from kaggle "Life Style Data", it captures detailed personal, nutritional, and fitness-related data for 20,000 individuals with 54 features. It contains health parameters such as age, weight, and BMI; exercise variables including BPM, duration, and activity type; and nutritional information such as macronutrient breakdown and meal classifications. Several derived metrics further estimate calorie balance, lean body mass, and workout effectiveness.
The numeric target variable will be calories_burned.
The predictor variables:
Physiological: age, Gender, Weight (kg), Height (m), Fat_percentage, BMI, Resting_BPM
Workout: Session_duration (hours), Avg_BPM, Max_BPM, Workout_Type, Experience_Level, Workout_Frequency (day/week)
Lifestyle: Water_Intake (liters), diet_type
Project overview
The goal of this analysis will be to create machine learning models that estimates energy expenditure (calories_burned) of a user given their profile, session details and lifestlye habits.
The project addresses two distinct tasks:
Regression: Predicting the exact number of Calories_Burned.
Classification: Categorizing a workout as Low, Medium, or High intensity.
Part 2: Exploratory Data Analysis (EDA)
Data Cleaning: there were no missing value or duplicates allowing for robust modeling without data imputation.
Decriptive statistics:
Sessions last on average ~1.26 hours (SD ≈ 0.34), so most sessions are between ~0.9 and 1.6 hours.
Average calories burned per session is ~1280 kcal, with a wide spread (SD ≈ 500), indicating varying intensity/duration.
Workout frequency clusters around 3–4 days/week.
BMI ranges from about 12 to 50, with most users around 25, consistent with a mix of lean to overweight participants.
IQR-based analysis marked 507 sessions with Calories_Burned > 2516 kcal as outliers. These correspond to very long / intense sessions, which are still realistic in this dataset. I decided to keep these points, as they represent meaningful extreme workouts rather than data errors.
Taget Distribution:
Calories_Burned follows a bell-shaped (normal) distribution centered around 1280 calories. This confirmed that the target did not require logarithmic transformation.
Session Duration vs Calories Burned:
There is an extremely strong, positive linear relationship. The data points hug the red trendline very tightly. This confirms that time working out is a very good predictor. If you know how long someone worked out, you can guess their calorie burn with high accuracy.
Workout Type vs Calories Burned:
This box plot is used to compare the distribution of Calories_Burned across different Workout_Type categories (HIIT, Cardio, Strength, Yoga) to determine how the choice of activity influences energy expenditure and to validate Workout_Type as a meaningful categorical predictor.
There are distinct hierarchies in calorie burn. High-intensity activities (HIIT, strength) demonstrated higher medians and greater variance compared to Yoga and Cardio. This variability confirms that Workout_Type is a critical discriminator for the model, as it sets the "baseline" range for the expected calorie burn
Calories burned vs Heart Rate Measures:
Despite expectations based on real physiology, the dataset shows no clear relationship between Avg/Max BPM and Calories Burned. The scatterplots reveal that heart-rate values do not meaningfully explain calorie expenditure
Heatmap Correlation:
In order to quantify the predictive power of each feature and validate the visual trends, a correlation heatmap was generated to measure linear relationships between all numeric variables and the target. The analysis provided definitive evidence that Session_Duration is the dominant predictor ( 𝑟=0.81 ). Surprisingly, physiological features like Weight and BMI showed no correlation, suggesting that for this specific dataset, the "effort" (Time/Intensity) vastly outweighs the "body type" in determining energy expenditure.
Workout Frequency vs. Calories burned:
A box plot was generated to compare the distribution of calorie expenditure across these frequency groups to determine if the frequency of weekly exercise predicts the intensity (calorie burn) of individual sessions. A strong positive correlation ( 𝑟≈0.58 ) was found. Users who exercise more frequently (e.g., 5 days/week) demonstrate a significantly higher median calorie burn per session compared to less frequent exercisers. This suggests that Workout_Frequency is a valuable predictor of user performance and should be included in the predictive model.
Physique vs Calories Burned:
Here we can see that there are no clear trends, these graphs prove that physiological features have less of an affect on calories burned and therefore are not good predictive measures
Average Calories Burned by Diet Type:
The zoomed diet chart confirmed that while slight variations exist, no single diet correlates with significantly higher energy expenditure.
EDA Conclusion
Primary Predictors: Session_Duration Secondary Predictors: Workout_Frequency, Workout_Type, Experience_Level. Surprisingly context variables such as Age, Weight, Height and BMI did not show strong correlations Null: Diet_Type (confirmed as non-predictive, but kept for context).
Part 3: Baseline Model
1. Feature Selection & Preprocessing Based on the insights gathered during the EDA phase, I selected a comprehensive set of features to predict Calories_Burned:
Physiological Factors: Age, Weight, Height, BMI, Fat_Percentage, and Resting_BPM. These establish the user's basal metabolic baseline.
Workout Metrics: Session_Duration, Workout_Type, Workout_Frequency, Experience_Level, and Avg/Max BPM. These are the direct drivers of intensity.
Lifestyle Factors: Diet_Type and Water_Intake.
Data Transformation Pipeline:
Encoding: I applied One-Hot Encoding to categorical variables (Gender, Workout_Type, diet_type) with drop_first=True. This converts text labels into binary (0/1) columns suitable for regression while avoiding multicollinearity.
Train-Test Split: The dataset was split into Training (80%) and Testing (20%) sets. I used random_state=42 to ensure reproducibility.
Feature Scaling: I utilized StandardScaler to normalize numeric features (Mean=0, Std=1). Crucially, the scaler was fit only on the training data and then applied to the test data to prevent data leakage.
2. Model Training & Evaluation I trained a Linear Regression model to serve as the performance baseline. Despite its simplicity, the model performed exceptionally well, indicating a strong linear relationship between the selected features and energy expenditure.
Performance Metrics:
R² Score: 0.9669 (The model explains 96.7% of the variance in calorie burn).
MAE (Mean Absolute Error): 60.58 (Average prediction error is ~60 calories).
RMSE (Root Mean Squared Error): 90.91.
3. Visual Analysis & Feature Importance
Actual vs. Predicted:
The scatter plot of predictions vs. actual values shows a tight alignment with the red diagonal line, confirming high accuracy across the dataset range.
Residual Analysis (The Limitation):
While the metrics are strong, the residual plot reveals a slight "fan-shaped" pattern. This suggests the model underestimates calories for very high-intensity workouts and overestimates for some mid-range sessions. This non-linear behavior hints that while Linear Regression is a great baseline, tree-based models (like Random Forest) may capture these complex interactions better.
Coefficients (Feature Importance):
The analysis of model coefficients identified the primary drivers of calorie burn:
Top Positive Drivers: Workout_Type_HIIT and Session_Duration.
Top Negative Driver: Workout_Type_Yoga (lower intensity).
Secondary Drivers: Experience_Level, Weight, and BMI had meaningful but smaller impacts.
In conclustion Duration and Activity Type are the dominant predictors, validating the initial EDA findings.
Part 4: Feature Engineering
While the baseline Linear Regression model performed well ($R^2 \approx 0.967$), the residual analysis revealed curved patterns, suggesting that the relationship between predictors and calorie burn is non-linear. To address this and capture complex workout behaviors better, I engineered 6 new features before training advanced models.
1. Heart_Range
Measures a user's cardiovascular intensity range. Higher values indicate greater aerobic capacity or greater exertion during workouts.
2. Intensity_Volume
Captures the overall workout load, combining duration with heart-rate elevation. This approximates “total exertion,” an important driver of calorie burn.
3. Session_Duration_sq
Models non-linear duration effects. Longer workouts may produce diminishing or accelerating calorie returns, which this squared term allows the model to learn.
4. Weight_Duration
Heavier users require more energy to move their body mass, so combining weight with duration helps quantify physical workload.
5. BMI_Duration
Represents the joint effect of body composition and workout time, enabling models to capture variations in metabolic cost for different body types.
6. Fitness_Maturity
Age × Experience_Level Encodes the idea that experienced users of different ages may train differently. High Fitness_Maturity may correlate with better technique or more efficient energy use.
Together, these engineered features allow later models to: capture non-linear relationships, model interactions between physiology and workout behavior, better approximate total workout intensity, distinguish workout effects across different body types, represent expertise and long-term fitness development
After generating these features, the entire dataset (including new columns) underwent One-Hot Encoding and Standard Scaling to ensure compatibility with regression algorithms.
Clustering To incorporate body-composition patterns into the model, I applied K-Means clustering to key physiological attributes:
Age, Weight, Height, BMI, Fat Percentage, Resting BPM
Clustering improves significantly up to 4 groups
Beyond that, additional clusters do not meaningfully explain more variation
Thus, k = 4 is the optimal and most interpretable choice
Cluster Interpretations
The PCA visualization revealed four distinct user archetypes:
Cluster 0: Highest weight and highest BMI
Cluster 1: Lowest weight and lowest BMI (leanest users)
Cluster 2: Shorter users with average weight
Cluster 3: Tall users with higher weight but healthy BMI (likely more muscular)
These groupings allow models to understand shared metabolic characteristics, rather than relying solely on individual measurements.
Adding Cluster-Based Features to the Dataset
Physique_Cluster (categorical, one-hot encoded)
Represents body-composition group membership.
Physique_Dist (numeric)
Distance from each user to their cluster centroid, indicating how typical or atypical they are within their body type.
Part 5:Train and Evaluate Three Improved Models
After building the baseline regression model, the next step was to retrain and compare multiple models using the fully engineered feature set created in Part 4. This improved dataset included:
The six engineered numeric featuresm, Physique_Cluster (one-hot encoded), Physique_Dist, All original encoded and scaled variables
This richer feature representation allows more advanced models to detect complex, nonlinear relationships that Linear Regression cannot capture.
To ensure fairness, all models were trained on the exact same engineered dataset.
Improved Linear Regression: Retrained on the new feature set to serve as an updated benchmark.
Gradient Boosting Regressor: A powerful ensemble technique that builds trees sequentially to minimize errors.
Random Forest Regressor: A robust ensemble method that averages predictions from multiple decision trees to reduce overfitting and capture non-linearity.
I evaluated all models using MAE, RMSE, and R^2. The results demonstrated a massive performance gap between the linear and tree-based approaches.
Winning Model: Random Forest Regressor:
Based on all evaluation metrics, the Random Forest Regressor is the best-performing model: Lowest MAE (5.66): On average, predictions are off by less than 6 calories.Highest R^2 (0.999977): Explains virtually all variance in the target variable. While Linear Regression remained stagnant (RMSE ~89), the Random Forest model slashed the error to just ~2.37 calories, representing a near-perfect prediction capability.It successfully leveraged the engineered features and cluster structures to handle noise and feature interactions better than the other models.
Feature Importance Insights
To understand how the Random Forest makes predictions, I examined its top feature importances:

Session_Duration and its engineered non-linear variant (Session_Duration_sq) were the strongest predictors. Workout_Type (specifically Yoga and HIIT) played a major role, confirming that different activities have distinct metabolic profiles encoded in the data. The engineered feature Fitness_Maturity was quite influential, proving that combining demographic and behavioral data improves accuracy. The Heart Rate Anomaly: Interestingly, heart-rate features showed relatively low importance compared to duration. This validates my earlier EDA finding that this dataset prioritizes Duration and Activity Type over physiological features such as heart-rate, BMI and Weight
Part 6: Pickle file of winning model
Download Winning Regression Model (.pkl)
Part 7: Regression to Classification
7.1 Converting the Regression Target into Classes
In this section, I reframed the original regression problem (predicting exact calories burned) into a three-class classification problem. Instead of predicting a continuous number, the goal becomes identifying whether a workout results in:
Low calorie burn
Medium calorie burn
High calorie burn
To create these categories, I used quantile binning, computing the 33rd and 66th percentiles on the training target values:
Low Burn (Class 0): ≤ 1008 calories
Medium Burn (Class 1): 1008–1421.98 calories
High Burn (Class 2): > 1421.98 calories
This approach is more informative than a simple median split because it distinguishes three distinct workout intensities rather than just “low vs high.” It also ensures the classes remain balanced, preventing the classifier from being biased toward any single calorie range.
I rebuilt the entire feature-engineering pipeline from Part 4 (engineered features, scaling, clustering, and encoding) to maintain consistency between regression and classification tasks.
7.2 Class Balance Check
Before training classification models, I examined the class distribution in both training and test sets.
Training Set Distribution:
Class 0 (Low): ~33.4%
Class 1 (Medium): ~33.3%
Class 2 (High): ~33.3%
Testing Set Distribution:
Class 0 (Low): ~33.9%
Class 1 (Medium): ~32.6%
Class 2 (High): ~33.6%
Because all three classes represent approximately one-third of the dataset, no class is under-represented, and no rebalancing was required.
Since the classes are balanced:
Accuracy is a reliable metric for evaluating model performance
I will still examine Precision, Recall, and F1-scores to confirm the model performs consistently for all classes (e.g., ensuring Medium is not confused with High)
Part 8: Train & Evaluate Classification Models 8.1: Precision vs Recall + Error Type Analysis
In this task, the goal is to classify workouts into Low, Medium, or High calorie burn. Because the classes represent different intensities of physical activity, the consequences of misclassification are not equal.
Precision is more important than recall in this context:
Predicting High Burn when the workout was actually Medium or Low gives users false confidence.
Users may feel justified eating extra calories, leading to weight gain or stalled progress.
Fitness applications must prioritize trust, and overestimating calorie burn is more harmful than underestimating it.
Therefore, the model should only predict High Burn when it is very certain, making precision the key metric.
False Positive vs False Negative
False Positive (more harmful): The model predicts High Burn like 800 calories, but the user actually burned only ~300 calories.
That means the User overeats = calorie surplus = contradicts fitness goals.
False Negative (less harmful): Model predicts Low Burn, but user actually burned High Burn.
The User may feel slightly discouraged, but physically they remain in a calorie deficit (which still supports weight loss).
Therefore False Positives are more dangerous than False Negatives which aligns with choosing precision as the priority metric.
8.2: Models Trained
Three classification models were trained using the engineered feature set:
1. Logistic Regression
A baseline linear classifier used to measure whether the classes are linearly separable.
2. Random Forest Classifier
An ensemble model that captures nonlinear interactions and benefits strongly from engineered features and cluster attributes.
3. Support Vector Machine (SVM)
A kernel-based model capable of modeling more complex class boundaries, useful for structured and high-dimensional datasets.
All models were trained on the same engineered and scaled dataset, including cluster features, to ensure a fair comparison.
8.3: Evaluation
Logistic Regression - Accuracy: 99.08%
Performs extremely well. Errors occur only between adjacent classes (Low-Medium, Medium-High). Never confuses Low-High, which is crucial for minimizing harmful misclassifications.
Random Forest Classifier - Accuracy: 99.88%
Near-perfect classification. Only ~5 mistakes out of 4,000 test samples. Nearly perfect precision, recall, and F1 across all classes. Confusion matrix shows almost no errors = extremely reliable. Best at avoiding High Burn false positives, the most important requirement.
Support Vector Machine - Accuracy: 97.88%
Still strong, but slightly weaker than the others. More confusion between Medium and High. Indicates difficulty with overlapping decision boundaries in engineered feature space.
8.4: Winner The Random Forest Classifier is the best-performing classification model because:
Highest Accuracy (99.88%)
Virtually zero misclassifications
Perfect precision for High Burn (critical error type)
Captures nonlinear patterns from engineered features and clustering
Most robust across all evaluation metrics
The trained Random Forest pipeline, including the scaler, clustering model, thresholds, and features, was saved into a pickle file for deployment or later use.
- Downloads last month
- 229

