Skip to content

About

Heart rate zone classification using stacking ensmble with hybrid machine learning (Random Forest and SVM) and Deep learning (MLP)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Heart Rate Zone Classification — Stacking Ensemble (RF + SVM → MLP)

project — Classifying short windows of heart-rate data into fitness zones using a stacking ensemble: Random Forest and SVM as base models, MLP as meta-model.


Elevator pitch

This repository demonstrates an end-to-end pipeline that converts wearable heart-rate data into reliable per-window heart-rate zone predictions using a stacking ensemble. The approach combines two complementary base learners (Random Forest and SVM) whose probabilistic outputs are used to train a compact MLP meta-model — all tuned with randomized hyperparameter search and validated with stratified folds. The result is a lightweight, accurate classifier suitable for on-device or near-device deployment in sports and health applications.


Dataset

  • File: dataset_training_withclass_edited.csv (noted path in notebook: /mnt/data/dataset_training_withclass_edited.csv)
  • Rows: 942
  • Columns: 4
  • Column names: Average BPM, Time (hh:mm:ss), Date, fatigue
  • Detected target column: fatigue.
  • Quick stats (Average BPM): min 0, 25% 126, median 147, 75% 161, max 198.

High-level pipeline

  1. Data loading & preprocessing
    • Load the CSV, parse timestamps, clean missing/outlier BPM values, and create short fixed-length windows (features computed per-window).
  2. Feature engineering (per window)
    • Time-domain stats such as mean, min, max, (and optionally std, IQR, delta/slope features).
  3. Base model hyperparameter tuning
    • Random Forest: RandomizedSearchCV with param_distributions=rf_param_grid, n_iter=20, scoring='f1_macro', cv=3. Best RF hyperparameters found: {'n_estimators': 100, 'min_samples_split': 2, 'min_samples_leaf': 2, 'max_depth': None, 'bootstrap': False}.
    • SVM (probability=True): RandomizedSearchCV with param_distributions=svm_param_grid, n_iter=10, scoring='f1_macro', cv=3. Best SVM hyperparameters found: {'kernel': 'linear', 'gamma': 'scale', 'C': 1}.
  4. Stacking strategy (manual stacking implemented in notebook)
    • Use StratifiedKFold(n_splits=5) to generate out-of-fold predict_proba for base models on training data and to generate base-model predict_proba on test data.
    • Construct stacked feature matrices S_train and S_test (shape = n_samples × (n_classes × n_base_models)), then scale and feed into the meta-model.
  5. Meta-model
    • sklearn.neural_network.MLPClassifier used as meta learner (compact MLP). The MLP is trained on stacked probabilistic features.
  6. Evaluation
    • Final evaluation performed on hold-out test set using accuracy, precision, recall, and macro F1; confusion matrix visualized.

Hyperparameter tuning & model selection

  • RandomizedSearchCV (Random Forest): n_iter=20, cv=3, scoring=f1_macro. Best params: {'n_estimators': 100, 'min_samples_split': 2, 'min_samples_leaf': 2, 'max_depth': None, 'bootstrap': False}.
  • RandomizedSearchCV (SVM): n_iter=10, cv=3, scoring=f1_macro. Best params: {'kernel': 'linear', 'gamma': 'scale', 'C': 1}.
  • Stacking folds: n_folds = 5 (StratifiedKFold for out-of-fold meta features).

Results

evaluation on testing data (Meta Model MLP)

  • Accuracy: 0.9841269841269841 (~98.41%)
  • Precision (macro / averaged): 0.986733958183129 (~98.67%)
  • Recall (macro / averaged): 0.9835796387520526 (~98.36%)
  • F1-Score (macro): 0.9848284635394545 (~98.48%)

Notes on results:

  • Confusion matrix and per-class metrics are available in the notebook and provide insight into which zones are occasionally confused (typically adjacent-intensity zones).
  • These high-level numbers come directly from the notebook's printed evaluation output — include them in your portfolio but also consider reporting per-class precision/recall when presenting to hiring teams.

How to reproduce (quick)

  1. Place dataset_training_withclass_edited.csv in the working directory (or update the notebook path). The notebook references /mnt/data/dataset_training_withclass_edited.csv.
  2. Create and activate a virtual environment and install required packages:
python -m venv .venv
source .venv/bin/activate   # macOS/Linux
.\.venv\Scripts\activate  # Windows
pip install -r requirements.txt
  1. Run the notebook (jupyter lab or jupyter notebook) and execute cells in order. The notebook performs the following steps automatically:

    • hyperparameter searches (RF: 20 candidates, SVM: 10 candidates — takes some time but is parallelized n_jobs=-1),
    • stacking generation (5-fold StratifiedKFold),
    • meta-model training and final evaluation.
  2. Export the notebook as IPYNB (File → Download as → IPYNB) and attach the confusion matrix & sample prediction plots in your application materials.


Contact

Muhammad 'Aamir Nashrullah — Machine Learning & Embedded Systems Engineer

  • Linkedin: www.linkedin.com/in/muhammad-aamir-nashrullah-bb39a7229
  • Email: arul.amir20@gmail.com
  • GitHub: https://github.com/Arulamir

License

EPL-2.0 License — see LICENSE for details.

About

Heart rate zone classification using stacking ensmble with hybrid machine learning (Random Forest and SVM) and Deep learning (MLP)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages