This project aims to classify human activities and postural transitions using smartphone sensor data. The dataset used is from the UCI Machine Learning Repository: Smartphone-Based Recognition of Human Activities & Postural Transitions. The dataset consists of accelerometer and gyroscope readings collected from a smartphone placed on subjects performing various activities.
Human activity recognition (HAR) has applications in healthcare monitoring, fitness tracking, and smart environments. By classifying activities such as walking, standing, and sitting, we can develop intelligent applications that assist users in daily life. This project focuses on training and optimizing machine learning models to accurately classify human activities based on smartphone sensor data.
- Source: UCI Machine Learning Repository
- Features: 561 features extracted from accelerometer and gyroscope data
- Classes: 12 human activities (e.g., Walking, Sitting, Standing, Lying Down, etc.)
- Training Samples: 7,767
- Testing Samples: 3,162
- Standing
- Sitting
- Lying down
- Walking
- Walking upstairs
- Walking downstairs
- Stand-to-sit
- Sit-to-stand
- Sit-to-lie
- Lie-to-sit
- Lie-to-stand
- Stand-to-lie
- The dataset is loaded from
dataset/Train/
anddataset/Test/
. - Features are normalized to a range between 0 and 1.
MATLAB Script: prepare_data.m
I have performed exploratory data analysis (EDA) to understand feature distributions and activity-wise feature separation. The following visualizations were used:
- Feature distribution plots to identify outliers.
- Class distribution bar charts to ensure balanced classes.
- Correlation heatmaps to check feature redundancy.
MATLAB Script: visualize_data.m
Three baseline models were trained to establish a starting point:
Model | Accuracy (%) |
---|---|
Decision Tree | 60.56 |
k-NN (k=5) | 87.25 |
SVM (Linear) | 89.88 |
- k-NN and SVM performed well, but Decision Tree had low accuracy.
MATLAB Script:train_models.m
We experimented with different approaches to improve model performance:
- k-NN: We tested different values of k and found k=7 optimal.
- SVM: We experimented with different kernel functions (
linear
,polynomial
,rbf
) and values of C (Regularization Parameter).
We attempted multiple feature selection strategies:
- Top 20 Features → Slight improvement in Decision Tree, but k-NN and SVM accuracy dropped.
- Top 30 Features → Improved k-NN accuracy, but SVM performance dropped significantly.
- Recursive Feature Elimination (RFE) → Selected 560 most relevant features, improving overall accuracy.
After performing RFE-based feature selection and advanced hyperparameter tuning, the final model was trained using SVM with C=10 and a linear kernel.
Model | Accuracy (%) |
---|---|
Final SVM Model (C=10, Linear) | 91.77 |
- The confusion matrix revealed strong classification performance, especially in static activities.
- Some misclassification occurred in transitions like
sit-to-stand
andstand-to-lie
.
These metrics provided additional insights into per-class performance, helping analyze strengths and weaknesses.
# Clone the repository
https://github.com/Pratham-mehta/human-activity-recognition-matlab.git
cd smartphone-activity-recognition
- Go to MATLAB Online
- Upload the dataset and scripts
- Visualize Data:
visualize_data.m
- Prepare the Data:
prepare_data.m
- Train Initial Models:
train_models.m
- Hyperparameter Tuning:
tune_knn.m
,tune_svm.m
- Feature Selection:
compute_feature_importance.m
,select_features.m
,rfe_feature_selection.m
- Train Final Model:
train_models_selected.m
- Evaluate Final Model:
evaluate_final_svm.m
human-activity-recognition-matlab/
│── dataset/ # Raw dataset
│ ├── Train/
│ ├── Test/
│ ├── features.txt
│── visualize_data.m # Data visualization script
│── prepare_data.m # Data preprocessing script
│── train_models.m # Initial model training
│── tune_knn.m # k-NN Hyperparameter tuning
│── tune_svm.m # SVM Hyperparameter tuning
│── compute_feature_importance.m # Feature importance analysis
│── select_features.m # Feature selection based on importance
│── rfe_feature_selection.m # Recursive Feature Elimination (RFE)
│── tune_svm_advanced.m # Advanced SVM tuning (C & Kernel)
│── train_models_selected.m # Final training on selected features
│── evaluate_final_svm.m # Final model evaluation and metrics
│── README.md # Documentation
- Feature selection is critical – Selecting the right features improved Decision Tree performance but initially hurt SVM and k-NN.
- Hyperparameter tuning is essential – Fine-tuning
k
in k-NN andC, Kernel
in SVM significantly improved accuracy. - RFE is powerful – Recursive Feature Elimination helped retain 560 best features, boosting SVM accuracy to 91.77%.
- Confusion matrices help analysis – We identified where misclassifications occurred and addressed them.
- Deep Learning Approach: Testing LSTM-based HAR models for sequence-based activity recognition.
- On-Device Deployment: Implementing lightweight models for real-time classification on smartphones.
- Data Augmentation: Using synthetic data generation to improve classifier robustness.
Want to contribute or have questions? Feel free to reach out!
📧 Email: pm3483@nyu.edu 🔗 GitHub: Pratham-mehta
Let's build smarter activity recognition systems together!