Automatic behavior monitoring technologies are becoming part of our everyday lives thanks to advances in sensors and machine learning. The automatic analysis and understanding of behavior are being applied to solve problems in several fields, including health care, sports, marketing, ecology, security, and psychology, to name a few. This book provides a practical introduction to machine learning methods applied to behavior analysis with the R programming language. The book does not assume any previous knowledge in machine learning. You should be familiar with the basics of R and some knowledge in basic statistics and high school-level mathematics would be beneficial.

Supplemental Material

Supplemental material consists of the examples’ code and datasets. The source code for the examples can be downloaded from Instructions on how to set up the code and get the datasets are in Appendix A. A reference for all the utilized datasets is in Appendix B.


DATASET names are written in uppercase italics. Functions are referred to by their name followed by parenthesis and omitting their arguments, for example: myFunction(). Class labels are written in italics and between single quotes: ‘label1’. The following icons are used to provide additional contextual information:

Provides additional information and notes.
Important information to consider.
Provides tips and good practice recommendations.
Lists the R scripts and files used in the corresponding section.
Interactive shiny app available. Please see Appendix A for instructions on how to run shiny apps.

The folder icon will appear at the beginning of a section (if applicable) to indicate which scripts were used for the corresponding examples.


I want to thank Michael Riegler, Jaime Mondragon y Ariana, Viviana M., Linda Sicilia, Anton Aguilar, Aleksander Karlsen, my former master’s and PhD. advisor Ramon F. Brena, and my colleagues at SINTEF.

The examples in this book rely heavily on datasets. I want to thank all the people that made all their datasets used here publicly available. I want to thank Vance Capley who brought to life the front cover and comic illustrations.