A machine learning pipeline for detecting fine-scale behavioral events in bio-logging data.

Installation

You can install the development version of rstickleback from GitHub with:

# install.packages("devtools")
devtools::install_github("FlukeAndFeather/rstickleback")

Key concepts

  • Behavioral events are brief behaviors that can be represented as a point in time, e.g. feeding or social interactions.
  • High-resolution bio-logging data (e.g. from accelerometers and magnetometers) are multi-variate time series. Traditional classifiers struggle with time series data.
  • stickleback takes a time series classification approach to detect behavioral events in longitudinal bio-logging data.

Quick start

Load sample data

The included sensor data contains the depth, pitch, roll, and speed of six blue whales at 10 Hz, and the event data contains the times of lunge-feeding behaviors.

library(rstickleback)
# `load_lunges()` returns a list of sensors and events, so we use the multiple
# assignment operator (%<-%) to destruct the list into separate `lunge_sensors`
# and `lunge_events` objects.
c(lunge_sensors, lunge_events) %<-% load_lunges()

# Again we use %<-%, to divide the sensors and events into test and train sets
test_deployids <- deployments(lunge_sensors)[1:3]
c(sensors_test, sensors_train) %<-% divide(lunge_sensors, test_deployids)
c(events_test, events_train) %<-% divide(lunge_events, test_deployids)

Visualize sensor and event data

sb_plot_data() produces an interactive figure for exploring bio-logger data.

deployid <- deployments(lunge_sensors)[1]
sb_plot_data(deployid, lunge_sensors, lunge_events)

Animated loop of interactively exploring data with sb_plot_data()

Define model

Initialize a Stickleback model using Supervised Time Series Forests and a 5 s window.

tsc <- compose_tsc(module = "interval_based", 
                   algorithm = "SupervisedTimeSeriesForest",
                   params = list(n_estimators = 2L, random_state = 4321L),
                   columns = columns(lunge_sensors))
sb <- Stickleback(tsc, 
                  win_size = 50, 
                  tol = 5, 
                  nth = 10, 
                  n_folds = 4, 
                  seed = 1234)

Fit model

Fit the Stickleback object to the training data.

sb_fit(sb, sensors_train, events_train)

Generate predictions

Make predictions on the test data and assess prediction outcomes.

predictions <- sb_predict(sb, sensors_test)
outcomes <- sb_assess(sb, predictions, events_test)
outcomes
#> Outcomes 
#> # A tibble: 3 × 4
#>   deployid       TP    FP    FN
#>   <chr>       <int> <int> <int>
#> 1 bw180905-42    45     7     1
#> 2 bw180905-49    42     0     2
#> 3 bw180905-53    26     4     0

Visualize sensor and event data

sb_plot_predictions() produces an interactive figure for exploring model predictions.

deployid <- deployments(sensors_test)[1]
sb_plot_predictions(deployid, sensors_test, predictions, outcomes)

Animated loop of interactively examining predictions with sb_plot_predictions()