This repository contains the code for processing and classifying accelerometer data from binary files. The script processes raw accelerometer data, extracts features, and classifies the data using a trained Random Forest model. It also detects non-wear periods and labels changes between upright and non-upright body positions.
-
Clone the repository:
git clone https://github.com/Ingemar28/CP-Movetime-app-classifier.git cd CP-Movetime-app-classifier -
Install the required Python packages:
pip install -r requirements.txt
-
Prepare your input data:
- Place your binary
.binfiles in an input folder. - Ensure that the folder paths are correct when prompted by the script.
- Place your binary
-
Run the script:
python scripts/classify.py
-
The script will prompt you to enter the paths to your input and output folders:
Please enter the path to your input folder containing .bin files: <path_to_input_folder> Please enter the path to your output folder: <path_to_output_folder> -
The script will process each
.binfile in the input folder, extract features, and classify the data. The results will be saved as CSV files in the output folder.
-
Read Binary Files:
- The
read_binary_filefunction reads binary files and converts them to a pandas DataFrame.
- The
-
Smooth the Data:
- The
smoothing_datafunction smooths the accelerometer data using a rolling mean.
- The
-
Segment Data and Extract Features:
- The
window_featuresfunction segments the data into windows and extracts features using theextract_acc_fetfunction.
- The
-
Predict Using the Trained Model:
- The script uses a pre-trained Random Forest model to predict the activity for each window of data.
-
Detect Non-Wear Periods:
- The
detect_non_wear_periodsfunction identifies non-wear periods based on the standard deviation of the accelerometer data.
- The
-
Label Changes Between Upright and Non-Upright Positions:
- The script labels changes in body position (e.g., standing up, sitting down) based on the predicted activities.
-
Save the Results:
- The results are saved to CSV files in the specified output folder.