Skip to main content

Sklearn flavored library containing numerous Activity of Daily Livings datasets, preprocessing methods, visualizations and models.

Project description

Activities of Daily Living - Machine Learning

Contains data preprocessing and visualization methods for ADL datasets.

PyPI version Download Stats Read the Docs (version) License

Activities of Daily living (ADLs) such as eating, working, sleeping and Smart Home device readings are recorded by inhabitants. Predicting resident activities based on the device event-stream allows for a range of applications, including automation, action recommendation and abnormal activity detection in the context of assisted living for elderly inhabitants. Pyadlml offers an easy way to fetch, visualize and preprocess common datasets.

!! Disclaimer !!

Package is still an alpha-version and under active development. As of now do not expect anything to work! APIs are going to change, stuff breaks and the documentation may lack behind. Nevertheless, feel free to take a look. The safest point to start is probably the API reference.

Last (stable) Release

$ pip install pyadlml

Latest Development Changes

$ git clone https://github.com/tcsvn/pyadlml
$ cd pyadlml
$ pip install .

Usage example

Simple

# Fetch dataset
from pyadlml.dataset import fetch_amsterdam
data = fetch_amsterdam()
df_devs, df_acts = data['devices'], data['activities']


# Plot the residents activity density over one day
from pyadlml.plot import plot_activity_density
fig = plot_activity_density(df_acts)
fig.show()


# Create a vector representing the state of all Smart Home devices
# at a certain time and discretize the events into 20 second bins
from pyadlml.preprocessing import StateVectorEncoder, LabelMatcher
sve = StateVectorEncoder(encode='raw', dt='20s')
raw = sve.fit_transform(df_devs)

# Label each datum with the corresponding activity.
# When an event matches no activity set the activity to "other"
lbls = LabelMatcher(other=True).fit_transform(df_acts, raw)

# Extract numpy arrays without timestamps (1st column)
X, y = raw.values[:,1:], lbls.values[:,1:]

# Proceed with machine learning stuff 
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X, y)
clf.score(X, y)
...

Less simple

from pyadlml.dataset import fetch_amsterdam
from pyadlml.constants import VALUE
from pyadlml.pipeline import Pipeline
from pyadlml.preprocessing import IndexEncoder, LabelMatcher, DropTimeIndex, \
                                  EventWindows, DropColumn
from pyadlml.model_selection import train_test_split
from pyadlml.model import WaveNet
from pyadlml.dataset.torch import TorchDataset
from torch.utils.data import DataLoader
from torch.optim import Adam 
from torch.nn import functional as F

# Featch data and split into train/val/test based on time rather than #events
data = fetch_amsterdam()
X_train, X_val, X_test, y_train, y_val, y_test = train_test_split(
    data['devices'], data['activities'], \
    split=(0.6, 0.2, 0.2), temporal=True,
)

# Formulate all preprocessing steps using a sklearn styled pipeline 
pipe = Pipeline([
    ('enc', IndexEncoder()),            # Encode devices strings with indices
    ('drop_obs', DropColumn(VALUE)),    # Disregard device observations
    ('lbl', LabelMatcher(other=True)),  # Generate labels y  
    ('drop_time', DropTimeIndex()),     # Remove timestamps for x and y
    ('windows', EventWindows(           # Create sequences S with a sliding window
                  rep='many-to-one',    # Only one label y_i per sequence S_i
                  window_size=16,       # Each sequence contains 16 events 
                  stride=2)),           # A sequence is created every 2 events
    ('passthrough', 'passthrough')      # Do not use a classifier in the pipeline
])

# Create a dataset to sample from
dataset = TorchDataset(X_train, y_train, pipe) 
train_loader = DataLoader(dataset, batch_size=32, shuffle=True)
model = WaveNet(
    n_features=14,       # Number of devices
    n_classes=8          # Number of activities
)
optimizer = Adam(model.parameters(), lr=3e-4)

# Minimal loop to overfit the data
for s in range(10000):
    for (Xb, yb) in train_loader:
        optimizer.zero_grad()
        logits = model(Xb)
        loss = F.cross_entropy(logits, yb)
        loss.backward()
        optimizer.step()

...

For more examples and how to use, please refer to the documentation.

Features

  • Access to 14 Datasets
  • Importing data from Home Assistant or Activity Assistant
  • Tools for data cleaning
    • Relabel activities and devices
    • Merge overlapping activities
    • Find and replace specific patterns in device signals
    • Interactive dashboard for data exploration
  • Various statistics and visualizations for devices, activities and their interaction
  • Preprocessing methods
    • Device encoder (index, raw, changepoint, last_fired, ...)
    • Feature extraction (inter-event-times, intensity, time2vec, ...)
    • Sliding windows (event, temporal, explicit or fuzzytime)
    • Many more ...
  • Cross validation iterators and pipeline adapted for ADLs
    • LeaveKDayOutSplit, TimeSeriesSplit
    • Conditional transformer: YTransformer, XorYTransformer, ...
  • Ready to use models
    • RNNs
    • WaveNet
    • Transformer
  • Translate datasets to sktime formats

Supported Datasets

  • Amsterdam [1]
  • Aras [2]
  • Casas Aruba (2011) [3]
  • Casas Cairo [4]
  • Casas Milan (2009) [4]
  • Casas Tulum [4]
  • Casas Kyoto (2010) [4]
  • Kasteren House A,B,C [5]
  • MITLab [6]
  • UCI Adl Binary [8]
  • Chinokeeh [9]
  • Orange [TODO]

Examples, benchmarks and replications

The project includes a ranked model leaderboard evaluated on the cleaned dataset versions. Additionaly, here is a useful list of awesome references (todo include link) to papers and repos related to ADLs and machine learning.

Contributing

  1. Fork it (https://github.com/tcsvn/pyadlml/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Related projects

Support

Buy me a coffee

How to cite

If you are using pyadlml for publications consider citing the package

@software{pyadlml,
  author = {Christian Meier},
  title = {PyADLMl - Machine Learning library for Activities of Daily Living},    
  url = {https://github.com/tcsvn/pyadlml},
  version = {0.0.22-alpha},
  date = {2023-01-03}
}

Sources

Dataset

[1]: T.L.M. van Kasteren; A. K. Noulas; G. Englebienne and B.J.A. Kroese, Tenth International Conference on Ubiquitous Computing 2008
[2]: H. Alemdar, H. Ertan, O.D. Incel, C. Ersoy, ARAS Human Activity Datasets in Multiple Homes with Multiple Residents, Pervasive Health, Venice, May 2013.
[3,4]: WSU CASAS smart home project: D. Cook. Learning setting-generalized activity models for smart spaces. IEEE Intelligent Systems, 2011.
[5]: Transferring Knowledge of Activity Recognition across Sensor networks. Eighth International Conference on Pervasive Computing. Helsinki, Finland, 2010.
[6]: E. Munguia Tapia. Activity Recognition in the Home Setting Using Simple and Ubiquitous sensors. S.M Thesis
[7]: Activity Recognition in Smart Home Environments using Hidden Markov Models. Bachelor Thesis. Uni Tuebingen.
[8]: Ordonez, F.J.; de Toledo, P.; Sanchis, A. Activity Recognition Using Hybrid Generative/Discriminative Models on Home Environments Using Binary Sensors. Sensors 2013, 13, 5460-5477.
[9]: D. Cook and M. Schmitter-Edgecombe, Assessing the quality of activities in a smart environment. Methods of information in Medicine, 2009

Software

TODO add software used in TPPs

License

MIT © tcsvn

sdf

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyadlml-0.0.7.25a0.tar.gz (267.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyadlml-0.0.7.25a0-py3-none-any.whl (326.8 kB view details)

Uploaded Python 3

File details

Details for the file pyadlml-0.0.7.25a0.tar.gz.

File metadata

  • Download URL: pyadlml-0.0.7.25a0.tar.gz
  • Upload date:
  • Size: 267.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pyadlml-0.0.7.25a0.tar.gz
Algorithm Hash digest
SHA256 1372640eac4c76e046211d9e1ac44a2aedb4a90eaf584b7b9a7d328f5a0dd784
MD5 46f7c79e460d82bc69a84dcf2599f9db
BLAKE2b-256 94bd7a1f647e0c0f313d7626df37c05754fb71be4c18892ffcd2f067ae2d9b5b

See more details on using hashes here.

File details

Details for the file pyadlml-0.0.7.25a0-py3-none-any.whl.

File metadata

  • Download URL: pyadlml-0.0.7.25a0-py3-none-any.whl
  • Upload date:
  • Size: 326.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for pyadlml-0.0.7.25a0-py3-none-any.whl
Algorithm Hash digest
SHA256 5df222613c8aeee3fc04177f9b76752d114c711beacd595f5707221a98421879
MD5 2c74b86076606a67923ed4d69bfd28c5
BLAKE2b-256 ff1075cbe60a41c78885e26168947fc8a56a3430ab05ff6479b77f78baebd66f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page