Research · Sensor data · Time series · Classification · 2023

Human activity recognition from smartphone inertial sensors

Classifying six daily activities from waist-mounted accelerometer and gyroscope signals — five classical models under grid search, a deep-learning pass, and what the subject split teaches about validation.


Problem

Given a window of inertial sensor readings from a phone on a person’s waist, say which of six activities they’re doing: walking, walking upstairs, walking downstairs, sitting, standing, or lying down. It’s the canonical “what is the phone’s owner doing” problem behind step counters, fall detection and context-aware UI — and a clean test of whether a classifier can separate postures that look nearly identical to an accelerometer.

Data

The UCI Human Activity Recognition dataset: 30 subjects aged 19–48, a Samsung Galaxy S II at the waist, 3-axis linear acceleration and 3-axis angular velocity at 50 Hz, video-labelled. Signals were noise-filtered, split into 2.56-second windows with 50 % overlap (128 readings each), and the acceleration separated into body and gravity components with a 0.3 Hz Butterworth low-pass. Each window carries 561 engineered features — time-domain and frequency-domain statistics over the body, gravity, jerk and magnitude signals. 10,299 windows in total; no missing values.

Exploration

That exploration set the expectation for the models: anything reasonable will get the dynamic/static split; the score is decided by sitting vs. standing.

Models

Five classifiers, each in a scaler-plus-model pipeline, tuned with 5-fold grid search on a 70/30 split:

ModelBest configurationCV accuracyTrain accuracyNote
Logistic regressionL2, C = 1, multinomial98.3 %99.7 %Best overall; the features are close to linearly separable
SVM (RBF)C / γ gridhigh—Competitive with logistic regression
kNNk = 195.6 %100 %k = 1 chosen by the grid — a memoriser, not a model
Random Forestdepth 6, 6 leaves, 50 trees88.5 %88.4 %Grid was deliberately shallow; under-fit, not over-fit
Gaussian NB—65.1 %65.8 %Feature independence assumption fails badly on 561 correlated features

Comparison plots covered train vs. test score, fit time, precision/recall/F1, and per-class ROC. A Keras dense network was also fitted as a deep-learning baseline.

What the results actually say

The validation lesson

The dataset ships with a split by subject — 70 % of the volunteers train, 30 % test — precisely so a model is scored on people it has never seen. The notebook re-split the pooled data randomly by window, which puts every subject in both train and test and lets the model learn individual gait signatures. The scores above are therefore optimistic. The right protocol is group-aware: hold out subjects (GroupKFold or leave-one-subject-out), which is also the protocol that predicts how the model behaves on a new phone owner. This is the same lesson as the taxi project in a different costume: the split has to match the deployment.

What I’d do differently

← All research