Package: pyadlml
Activities of Daily Living - Machine LearningContains data preprocessing and visualization methods for ADL datasets.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$pipinstallpyadlmlLatest Development Changes$gitclonehttps://github.com/tcsvn/pyadlml
$cdpyadlml
$pipinstall.Usage exampleSimple# Fetch datasetfrompyadlml.datasetimportfetch_amsterdamdata=fetch_amsterdam()df_devs,df_acts=data['devices'],data['activities']# Plot the residents activity density over one dayfrompyadlml.plotimportplot_activity_densityfig=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 binsfrompyadlml.preprocessingimportEvent2Vec,LabelMatchere2v=Event2Vec(encode='state',dt='20s')states=e2v.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,states)# Extract numpy arrays without timestamps (1st column)X,y=states.values[:,1:],lbls.values[:,1:]# Proceed with machine learning stufffromsklearn.treeimportDecisionTreeClassifierclf=DecisionTreeClassifier()clf.fit(X,y)clf.score(X,y)...Less simplefrompyadlml.datasetimportfetch_amsterdamfrompyadlml.constantsimportVALUEfrompyadlml.pipelineimportPipelinefrompyadlml.preprocessingimportIndexEncoder,LabelMatcher,DropTimeIndex,\EventWindows,DropColumnfrompyadlml.model_selectionimporttrain_test_splitfrompyadlml.modelimportDilatedModelfrompyadlml.dataset.torchimportTorchDatasetfromtorch.utils.dataimportDataLoaderfromtorch.optimimportAdamfromtorch.nnimportfunctionalasF# Featch data and split into train/val/test based on time rather than #eventsdata=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 pipelinepipe=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 windowrep='many-to-one',# Only one label y_i per sequence S_iwindow_size=16,# Each sequence contains 16 eventsstride=2)),# A sequence is created every 2 events('passthrough','passthrough')# Do not use a classifier in the pipeline])# Create a dataset to sample fromdataset=TorchDataset(X_train,y_train,pipe)train_loader=DataLoader(dataset,batch_size=32,shuffle=True)model=DilatedModel(n_features=14,# Number of devicesn_classes=8# Number of activities)optimizer=Adam(model.parameters(),lr=3e-4)# Minimal loop to overfit the dataforsinrange(10000):for(Xb,yb)intrain_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 thedocumentation.FeaturesAccess to 14 DatasetsImporting data fromHome AssistantorActivity AssistantTools for data cleaningRelabel activities and devicesMerge overlapping activitiesFind and replace specific patterns in device signalsInteractive dashboard for data explorationVarious statistics and visualizations for devices, activities and their interactionPreprocessing methodsDevice encoder (index, state, 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 ADLsLeaveKDayOutSplit, TimeSeriesSplitConditional transformer: YTransformer, XorYTransformer, ...Online metrics to compare models regardless of resample frequencyAccuracy, TPR, PPV, ConfMat, CalibrationReady to use models (TODO)RNNsWaveNetTransformerTranslate datasets to sktime formatsSupported DatasetsAmsterdam [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 replicationsThe project includes (TODO) 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.ContributingFork it (https://github.com/tcsvn/pyadlml/fork)Create your feature branch (git checkout -b feature/fooBar)Commit your changes (git commit -am 'Add some fooBar')Push to the branch (git push origin feature/fooBar)Create a new Pull RequestRelated projectsActivity Assistant- Recording, predicting ADLs within Home assistant.Sci-kit learn- The main inspiration and some borrowed source code.SupportHow to citeIf 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}
}SourcesDataset[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, 2009SoftwareTODO add software used in TPPsLicenseMIT  ©tcsvnsdf