Data#
Description for the data#
The available data consist of 5 signals (accelerometer z, x&y, and 3-axes gyroscope) recorded on 8 individuals with a sampling frequency of 16 Hz, what means that each signal has been measured 16 times per second.
For example, if the signals were recorded during 15 minutes for a given individual, a total of (15*60 (secs))*16 = 14400 measures are taken, therefore, we will have a vector of 14400 observations (data points) of each signal for that individual.
The recording time of each signal for each person was lower than 20 minutes.
Along with the signals the activity carried out by the individuals in each considered fraction of time was also registered.
Predictors: the signals.
Response: the activities.
Besides, we have data regarding the signals for 2 additional individuals whose activity was not registered. One of the task will be to recognize what kind of activity those people were doing in each second of the recorded time. This data will play the role of new data to be predicted.
Understanding the data#
The dat is encapsulated as a Matlab
file. We can load it using loadmat
from scipy
.
# Load the .mat file
HAR_database = loadmat(r'C:\Users\fscielzo\Documents\DataScience-GitHub\Human-Activity-Recognition\HAR_database\HAR_database.mat')
HAR_database
is a dictionary with the following aspect:
HAR_database
{'__header__': b'MATLAB 5.0 MAT-file, Platform: MACI64, Created on: Tue May 16 10:33:21 2017',
'__version__': '1.0',
'__globals__': [],
'database_training': array([[array([[ 0.02417325, 0.01990478, 0.03474859, ..., 0.15302195,
0.16644707, 0.13097667],
[ 0.59441693, 0.60247182, 0.52582067, ..., 1.9454901 ,
2.00124793, 1.9890223 ],
[-0.02273627, -0.01287489, -0.0200163 , ..., 0.00468276,
-0.00249675, -0.00409452],
[ 0.11196179, 0.10379559, 0.10319319, ..., 0.11359097,
0.10181863, 0.10699662],
[ 0.06049883, 0.05515676, 0.05754055, ..., 0.04945955,
0.06203927, 0.06837131]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.00614456, 0.09416632, 0.02556427, ..., 0.25846636,
0.26831659, 0.20932986],
[ 0.15163056, 0.27388097, 0.24967994, ..., 1.01129501,
1.00222655, 0.94156865],
[-0.02664025, -0.02277741, -0.00710769, ..., -0.02000222,
-0.0194218 , -0.01871779],
[-0.06663789, -0.08298231, -0.10177238, ..., -0.03517126,
-0.04314523, -0.04061162],
[ 0.24180082, 0.23684254, 0.24130693, ..., 0.24131465,
0.23414938, 0.24768909]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.01725369, 0.10293477, 0.10819053, ..., 0.71082619,
0.6902869 , 0.70998775],
[ 0.68158121, 0.69141197, 0.79265585, ..., 0.84186193,
0.8235402 , 0.832608 ],
[ 0.02417523, 0.04607177, 0.03142754, ..., 0.01269511,
0.00978901, 0.00814963],
[-0.02421756, 0.01368092, -0.01676861, ..., -0.05873524,
-0.04761158, -0.04766088],
[-0.26560293, -0.25658879, -0.26265961, ..., -0.11135749,
-0.10438768, -0.10152 ]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.05165687, 0.0650987 , 0.01206259, ..., 0.36555553,
0.26527593, 0.34085031],
[ 0.47503658, 0.55140002, 0.55872758, ..., 1.42290122,
1.47060901, 1.4077758 ],
[ 0.13336841, 0.14036369, 0.13732303, ..., -0.07003494,
-0.07251649, -0.08866671],
[-0.0668408 , -0.07284105, -0.07443974, ..., 0.04751965,
0.04598145, 0.02407247],
[-0.16202343, -0.17998271, -0.20182392, ..., -0.21302053,
-0.23778129, -0.25154395]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.08256422, 0.09021634, 0.20833665, ..., 0.37585218,
0.44981253, 0.40607189],
[ 0.53693504, 0.51929183, 0.63409263, ..., 0.83708194,
0.8103373 , 0.7628346 ],
[ 0.05353819, 0.06431957, 0.11584413, ..., 0.09322134,
0.08182516, 0.08842621],
[ 0.02346034, 0.00344841, 0.05940777, ..., 0.02335576,
0.00431765, 0.02563387],
[-0.20278839, -0.22155068, -0.31653986, ..., -0.2931038 ,
-0.22910937, -0.18418657]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.01256814, 1.075318 , -0.8095081 , ..., 0.04081069,
0.27214215, 0.14404119],
[ 1.29229521, 2.2547067 , 2.32276895, ..., 0.88879623,
0.5977003 , 0.69151805],
[-0.08342359, -0.23339688, -0.4362292 , ..., -0.05970851,
-0.10780427, -0.08269408],
[-0.02199893, 0.03932658, 0.17018843, ..., 0.01902898,
0.01298154, -0.01913849],
[-0.20233026, -0.12446777, -0.09608618, ..., 0.39916403,
0.32787735, 0.12517909]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.06971024, 0.06352591, 0.07675852, ..., 0.27126796,
0.16124686, 0.19524657],
[ 0.39471738, 0.40493709, 0.43956792, ..., 1.27376087,
1.31028354, 1.25608528],
[-0.11659078, -0.11212781, -0.10438286, ..., -0.06724237,
-0.08350385, -0.06953112],
[ 0.06578621, 0.0653771 , 0.06778922, ..., 0.09091548,
0.09260207, 0.09608102],
[ 0.06120889, 0.05849763, 0.05579525, ..., 0.06037664,
0.05157136, 0.03467293]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.32805745, 0.21316135, 0.07730691, ..., 0.58396364,
0.57248017, 0.58201507],
[ 1.10277907, 0.94095768, 0.89902692, ..., 1.84413557,
1.78376892, 1.81727352],
[-0.07742709, -0.07919505, -0.08941372, ..., -0.0736645 ,
-0.07339881, -0.08894767],
[-0.07629876, -0.10038392, -0.10460145, ..., -0.10174 ,
-0.08993586, -0.09181229],
[ 0.08240638, 0.06781832, 0.06951888, ..., 0.08128702,
0.05290613, 0.06649676]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)]], dtype=object),
'database_test': array([[array([[-0.06516976, 0.0188162 , 0.02866381, ..., -0.65489655,
-0.50250338, -0.59326978],
[ 0.38268988, 0.56415602, 0.53441247, ..., 3.26943227,
3.36463946, 3.41075882],
[-0.2133753 , 0.05981534, 0.10957474, ..., -0.04022603,
-0.03728265, -0.01322535],
[ 0.18997728, 0.09126936, 0.06215636, ..., 0.11363941,
0.09155738, 0.10077387],
[ 0.13234735, 0.12937823, 0.15868741, ..., 0.0875492 ,
0.0407315 , 0.06236758]]) ],
[array([[-8.41940561e-01, -3.53763629e-02, -3.64637935e-01, ...,
-4.72952179e-03, -1.60836501e-02, 3.36982094e-03],
[ 1.22111782e+00, 1.60088113e+00, 1.29588646e+00, ...,
4.35754399e-01, 4.39480351e-01, 4.40240570e-01],
[-1.21402476e-01, -1.10038144e-01, 8.88294268e-03, ...,
-9.24688287e-02, -8.35644004e-02, -8.25075701e-02],
[-4.60425168e-03, -4.84477458e-02, -9.75501446e-02, ...,
-9.66818923e-02, -9.69218460e-02, -1.03798361e-01],
[ 3.65603734e-02, 1.50398948e-03, -1.90331775e-02, ...,
5.09622920e-02, 4.32677086e-02, 4.06927248e-02]]) ]],
dtype=object)}
The keys of HAR_database
are the following:
HAR_database.keys()
dict_keys(['__header__', '__version__', '__globals__', 'database_training', 'database_test'])
The available data for building the human activity recognition system is stored within database_training
, and is an array of arrays.
It has 8 arrays (one per individual), and each array has 2 arrays as columns, the first with the signals data, the second with the activity data.
HAR_database['database_training']
array([[array([[ 0.02417325, 0.01990478, 0.03474859, ..., 0.15302195,
0.16644707, 0.13097667],
[ 0.59441693, 0.60247182, 0.52582067, ..., 1.9454901 ,
2.00124793, 1.9890223 ],
[-0.02273627, -0.01287489, -0.0200163 , ..., 0.00468276,
-0.00249675, -0.00409452],
[ 0.11196179, 0.10379559, 0.10319319, ..., 0.11359097,
0.10181863, 0.10699662],
[ 0.06049883, 0.05515676, 0.05754055, ..., 0.04945955,
0.06203927, 0.06837131]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.00614456, 0.09416632, 0.02556427, ..., 0.25846636,
0.26831659, 0.20932986],
[ 0.15163056, 0.27388097, 0.24967994, ..., 1.01129501,
1.00222655, 0.94156865],
[-0.02664025, -0.02277741, -0.00710769, ..., -0.02000222,
-0.0194218 , -0.01871779],
[-0.06663789, -0.08298231, -0.10177238, ..., -0.03517126,
-0.04314523, -0.04061162],
[ 0.24180082, 0.23684254, 0.24130693, ..., 0.24131465,
0.23414938, 0.24768909]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.01725369, 0.10293477, 0.10819053, ..., 0.71082619,
0.6902869 , 0.70998775],
[ 0.68158121, 0.69141197, 0.79265585, ..., 0.84186193,
0.8235402 , 0.832608 ],
[ 0.02417523, 0.04607177, 0.03142754, ..., 0.01269511,
0.00978901, 0.00814963],
[-0.02421756, 0.01368092, -0.01676861, ..., -0.05873524,
-0.04761158, -0.04766088],
[-0.26560293, -0.25658879, -0.26265961, ..., -0.11135749,
-0.10438768, -0.10152 ]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.05165687, 0.0650987 , 0.01206259, ..., 0.36555553,
0.26527593, 0.34085031],
[ 0.47503658, 0.55140002, 0.55872758, ..., 1.42290122,
1.47060901, 1.4077758 ],
[ 0.13336841, 0.14036369, 0.13732303, ..., -0.07003494,
-0.07251649, -0.08866671],
[-0.0668408 , -0.07284105, -0.07443974, ..., 0.04751965,
0.04598145, 0.02407247],
[-0.16202343, -0.17998271, -0.20182392, ..., -0.21302053,
-0.23778129, -0.25154395]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.08256422, 0.09021634, 0.20833665, ..., 0.37585218,
0.44981253, 0.40607189],
[ 0.53693504, 0.51929183, 0.63409263, ..., 0.83708194,
0.8103373 , 0.7628346 ],
[ 0.05353819, 0.06431957, 0.11584413, ..., 0.09322134,
0.08182516, 0.08842621],
[ 0.02346034, 0.00344841, 0.05940777, ..., 0.02335576,
0.00431765, 0.02563387],
[-0.20278839, -0.22155068, -0.31653986, ..., -0.2931038 ,
-0.22910937, -0.18418657]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.01256814, 1.075318 , -0.8095081 , ..., 0.04081069,
0.27214215, 0.14404119],
[ 1.29229521, 2.2547067 , 2.32276895, ..., 0.88879623,
0.5977003 , 0.69151805],
[-0.08342359, -0.23339688, -0.4362292 , ..., -0.05970851,
-0.10780427, -0.08269408],
[-0.02199893, 0.03932658, 0.17018843, ..., 0.01902898,
0.01298154, -0.01913849],
[-0.20233026, -0.12446777, -0.09608618, ..., 0.39916403,
0.32787735, 0.12517909]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[ 0.06971024, 0.06352591, 0.07675852, ..., 0.27126796,
0.16124686, 0.19524657],
[ 0.39471738, 0.40493709, 0.43956792, ..., 1.27376087,
1.31028354, 1.25608528],
[-0.11659078, -0.11212781, -0.10438286, ..., -0.06724237,
-0.08350385, -0.06953112],
[ 0.06578621, 0.0653771 , 0.06778922, ..., 0.09091548,
0.09260207, 0.09608102],
[ 0.06120889, 0.05849763, 0.05579525, ..., 0.06037664,
0.05157136, 0.03467293]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)],
[array([[-0.32805745, 0.21316135, 0.07730691, ..., 0.58396364,
0.57248017, 0.58201507],
[ 1.10277907, 0.94095768, 0.89902692, ..., 1.84413557,
1.78376892, 1.81727352],
[-0.07742709, -0.07919505, -0.08941372, ..., -0.0736645 ,
-0.07339881, -0.08894767],
[-0.07629876, -0.10038392, -0.10460145, ..., -0.10174 ,
-0.08993586, -0.09181229],
[ 0.08240638, 0.06781832, 0.06951888, ..., 0.08128702,
0.05290613, 0.06649676]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)]], dtype=object)
HAR_database['database_training'].shape
(8, 2)
HAR_database['database_training'][0]
array([array([[ 0.02417325, 0.01990478, 0.03474859, ..., 0.15302195,
0.16644707, 0.13097667],
[ 0.59441693, 0.60247182, 0.52582067, ..., 1.9454901 ,
2.00124793, 1.9890223 ],
[-0.02273627, -0.01287489, -0.0200163 , ..., 0.00468276,
-0.00249675, -0.00409452],
[ 0.11196179, 0.10379559, 0.10319319, ..., 0.11359097,
0.10181863, 0.10699662],
[ 0.06049883, 0.05515676, 0.05754055, ..., 0.04945955,
0.06203927, 0.06837131]]) ,
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)], dtype=object)
For example, the array with the signals data for the first individual is the following:
HAR_database['database_training'][0][0]
array([[ 0.02417325, 0.01990478, 0.03474859, ..., 0.15302195,
0.16644707, 0.13097667],
[ 0.59441693, 0.60247182, 0.52582067, ..., 1.9454901 ,
2.00124793, 1.9890223 ],
[-0.02273627, -0.01287489, -0.0200163 , ..., 0.00468276,
-0.00249675, -0.00409452],
[ 0.11196179, 0.10379559, 0.10319319, ..., 0.11359097,
0.10181863, 0.10699662],
[ 0.06049883, 0.05515676, 0.05754055, ..., 0.04945955,
0.06203927, 0.06837131]])
There are 5 signals (rows) and 17736 measurements for each signals.
HAR_database['database_training'][0][0].shape
(5, 17736)
Since the sampling frequency of the signals is 16 Hz, which represents 16 measurements per second, the time during which the signals were recorded for the first individual is 17736 / 16 = 1108.5 seconds, what means 18.48 minutes. So, the recording time of the signals for the first individual was 18.48 minutes.
sampling_freq = 16
(HAR_database['database_training'][0][0].shape[1] / sampling_freq) / 60
18.475
The array with the activities of the first individual is the following.
HAR_database['database_training'][0][1]
array([[3, 3, 3, ..., 3, 3, 3]], dtype=uint8)
Is a 1D array (vector) with 17736 components, that represent measurements of activity.
HAR_database['database_training'][0][1].shape
(1, 17736)
The i-th component of that vector indicates the activity that the first individual was doing in that specific fraction of time within those 18.48 minutes. Since each point represent a tiny fraction of time (1/16 = 0.063 seconds, approximately), is reasonable to find the same activity repeated many times in a row. For example, if the individual was standing in the first 50 seconds of the recording, the vector would have a 3 (label for standing) in its first 50*16 = 800 components. In other words, the first 800 measurements fo activity would correspond to standing.