This repository contains R code to apply the activity classification models presented in the paper "Accelerometer-Based Classification of Walking, Running, and Jumping: A Machine Learning Approach for Mechanical Loading Assessment".
Before using this code, you need to:
- Install R (version 4.1.0 or higher) from https://cran.r-project.org/
- Install RStudio from https://posit.co/download/rstudio-desktop/
- Download this project (click the green "Code" button and select "Download ZIP")
- Unzip the downloaded file
- Open the
activity_recognition.Rprojfile. This should open the project in RStudio - In the RStudio Console, run:
install.packages("renv")
renv::restore()This will install all required packages.
- Open
main.Rin RStudio - Update these lines with your data details:
data <- vroom(
"path/to/your/data", # Replace with path to your CSV file
skip = 10 # Replace with number of header lines (0 if none)
)
results <- classify_activities(
data = data,
time_col = "timestamp", # Replace with your timestamp column name
x_col = "acc_x", # Replace with your X acceleration column name
y_col = "acc_y", # Replace with your Y acceleration column name
z_col = "acc_z", # Replace with your Z acceleration column name
sampling_freq = 100, # Replace with your sampling frequency in Hz
placement = "ankle", # Choose: "ankle", "lower_back", or "hip"
model_type = "rf" # Choose: "rf", "svm", or "knn"
)- Click the "Source" button (or press Ctrl+Shift+S) to run the analysis
- "File not found" error: Make sure the path to your CSV file is correct
- Column name errors: Check that your column names match exactly what you specified
- Package loading errors: Run
renv::restore()again to ensure all packages are installed
If you find any bugs or have questions, requests, or comments, please report them in this repository's issues page