Let's assume you have some data that has been labelled using the label_assistant
module. For the sake of this example, we will just use some dummy data and set some dummy labels manually.
df = pd.read_hdf('example_classified_data/labelled_behaviors.h5')
df.iloc[22:38].loc[:, ['behavior']] = 'foobar'
df.iloc[81:99].loc[:, ['behavior']] = 'baz'
df
The build_timeseries
function can be used to prepare the data for Keras. By defining the window_step_size
it is possible to model a sliding (default, step_size = 1
), hopping (1 < step_size < timeslice_length
), or a tumbling (step size < timeslice_length
) window.
features = [('head', 'x'), ('head', 'y'), ('tail', 'x')]
timeslice_length = 20
segmented_timeseries, label_vector = build_timeseries(df, features, timeslice_length, window_step_size=timeslice_length)
result_shape = segmented_timeseries.shape
test_eq(result_shape[0], 2)
test_eq(result_shape[1], 3)
test_eq(result_shape[2], timeslice_length)
As an alternative, we can build segments using a sliding window (which is used as the default).
features = [('head', 'x'), ('head', 'y'), ('tail', 'x')]
timeslice_length = 7
sliding_segmented_timeseries, sliding_label_vector = build_timeseries(df, features, timeslice_length)
result_shape = sliding_segmented_timeseries.shape
test_eq(result_shape[0], 43)
test_eq(result_shape[1], 3)
test_eq(result_shape[2], timeslice_length)
# segments that are indentified as `not_defined` are not included
test_eq(np.isin("not_defined", sliding_label_vector), False)