Upload your running data (speed & altitude) and get instant heart rate predictions in your browser. No installation required!
Model Description
This LSTM-based model predicts heart rate (BPM) from running workout data (speed and altitude). It's designed for runners training for sub-3-hour marathons to optimize their training by predicting physiological responses.
Model Architecture: 2-layer LSTM with 128 hidden units Parameters: ~206K trainable parameters Input Features: 14 engineered features (speed, altitude, gender + temporal features) Output: Time-series heart rate predictions in BPM
Intended Use
Primary Use Cases
Predict heart rate response during running workouts
Analyze training intensity without heart rate monitor
Plan workout zones based on speed/elevation profiles
Research on physiological modeling for endurance sports
V2 Model (this model): 7.42 BPM MAE (17% better than best V1!)
Example Predictions on Test Set
The model accurately predicts heart rate across different workout types:
Steady Pace Run - Consistent speed, stable HR response:
Steady Workout
Interval Training - Variable intensity with HR peaks:
Intervals Workout
Progressive Run - Gradually increasing pace and HR:
Progressive Workout
These are real predictions from the held-out test set (unseen during training).
Training Strategy
Dataset Preparation
Source: Endomondo HR dataset (public running workouts) Initial Size: 974 running workouts after quality filtering Final V2 Dataset: Enhanced with improved preprocessing
Key Improvements over V1:
Better Quality Filtering: Removed workouts with GPS errors, unrealistic HR values, or excessive missing data
Speed Computation: Calculated speed from GPS coordinates when missing, using haversine distance
Smoothing: Applied moving average to reduce sensor noise while preserving workout patterns
Feature Engineering (V2)
We engineered 14 features from the basic speed and altitude signals to capture physiological response patterns:
Base Features (3):
speed: Running speed (km/h) from GPS
altitude: Elevation (m) from GPS/barometer
gender: Binary encoding (1=male, 0=female)
Temporal Features (8):
Lag features: speed_lag_2, speed_lag_5, altitude_lag_30 - Heart rate responds to effort with a delay
Derivatives: speed_derivative, altitude_derivative - Acceleration and climbing rate
Rolling averages: rolling_speed_10, rolling_speed_30 - Sustained effort over 1-3 minutes
Additional lags: Medium and long-term effort tracking
Cumulative Features (3):
cumulative_elevation_gain: Total climbing (cumulative fatigue effect)
Short-term momentum features
Long-term elevation context
Why This Works: Heart rate doesn't respond instantly to speed changes. By including lagged features (what you were doing 12-180 seconds ago) and rolling averages (sustained effort), the model learns the delayed physiological response pattern.
Data Split:
Train: 70%
Validation: 15%
Test: 15%
Input Format
The model expects 14 features per timestep:
speed (km/h): Running speed from GPS
altitude (m): Elevation from GPS/barometer
gender (binary): 1=male, 0=female
speed_lag_2: Speed 2 timesteps ago (~12 seconds)
speed_lag_5: Speed 5 timesteps ago (~30 seconds)
altitude_lag_30: Altitude 30 timesteps ago (~3 minutes)
speed_derivative: Acceleration (change in speed)
altitude_derivative: Elevation change rate
rolling_speed_10: Moving average over 10 timesteps (~1 minute)
rolling_speed_30: Moving average over 30 timesteps (~3 minutes)
cumulative_elevation_gain: Total elevation gain so far (meters)
12-14. Additional temporal features: Enhanced lag and momentum features
Feature Engineering
Temporal features capture physiological response lag (heart rate responds to effort with 2-5 timestep delay) and cumulative fatigue (elevation gain).
Usage
Installation
pip install torch numpy pandas
Quick Start
python
1import torch
2import numpy as np
3from huggingface_hub import hf_hub_download
45# Download model files6checkpoint_path = hf_hub_download(7 repo_id="rricc22/heart-rate-prediction-lstm",8 filename="best_model.pt"9)1011# Load checkpoint12checkpoint = torch.load(checkpoint_path, map_location='cpu')1314# Load model architecture (you need to copy HeartRateLSTM_V2 class)15from lstm import HeartRateLSTM_V2
1617model = HeartRateLSTM_V2(18 input_size=14,19 hidden_size=128,20 num_layers=2,21 dropout=0.422)23model.load_state_dict(checkpoint['model_state_dict'])24model.eval()2526# Prepare input (example: 500 timesteps)27# You need to engineer features first (see feature_engineering.py)28features = torch.randn(1,500,14)# [batch=1, seq_len=500, features=14]2930# Predict31with torch.no_grad():32 predictions = model(features)# [1, 500, 1]3334heart_rate_bpm = predictions[0,:,0].numpy()
Feature Engineering
python
1from feature_engineering import engineer_features
23# Your workout data4workout ={5'speed':[10.5,11.2,10.8,...],# km/h6'altitude':[100,105,110,...],# meters7'gender':1.0# 1=male, 0=female8}910# Engineer all 14 features11features = engineer_features(workout)# [seq_len, 14]1213# Add batch dimension and convert to tensor14features_tensor = torch.from_numpy(features).unsqueeze(0)# [1, seq_len, 14]1516# Predict17with torch.no_grad():18 hr_predictions = model(features_tensor)
Limitations
Data Distribution: Trained on recreational runners (mostly European, Endomondo users)
Speed Range: Best performance for 8-15 km/h (training/marathon pace)
Sequence Length: Optimized for workouts 10-60 minutes (padded to 500 timesteps)
Individual Variation: Does not account for fitness level, age, or personal HR characteristics
Environmental Factors: Does not consider temperature, humidity, or wind
Bias and Fairness
Gender: Model includes binary gender feature (male/female) but may not capture non-binary individuals
Geographic: Dataset primarily from Europe, may not generalize to other populations
Fitness Level: Biased toward recreational runners training for marathons
Age: No explicit age modeling (dataset age distribution unknown)
Ethical Considerations
Not Medical Advice: This model is for research/training optimization only
Privacy: Do not use for surveillance or non-consensual monitoring
Safety: Athletes should still use proper HR monitors for safety-critical training
If you use this model in your research, please cite:
bibtex
1@software{heart_rate_lstm_v2_2026,
2 author = {Riccardo},
3 title = {Heart Rate Prediction from Running Data using LSTM},
4 year = {2026},
5 version = {2.0},
6 url = {https://huggingface.co/rricc22/heart-rate-prediction-lstm}
7}
Model Card Authors
Riccardo
Model Card Contact
For questions or issues, please open an issue on the repository.