Skip to main content

Machine learning for animal behavior analysis

Project description

codecov

BehaveML

Machine learning for animal behavior.

Interprets pose-tracking files (currently only from DLC) and behavior annotations (currently only from BORIS) to train a behavior classifier, perform unsupervised learning, and other common analysis tasks.

Installation

pip install behaveml

Can install optional extras with:

pip install numpy, cython
pip install behaveml[all]

This includes matplotlib, keras, and Linderman lab's state-space model package, ssm. Note that installing ssm requires cython and numpy for the build, so must be already present in the environment.

Quickstart

Import

from glob import glob 
from behaveml import VideosetDataFrame, clone_metadata
from behaveml import compute_dl_probability_features, compute_mars_features
from behaveml.io import get_sample_data_paths

Gather the DLC and BORIS tracking and annotation files

tracking_files, boris_files = get_sample_data_paths()

Setup some parameters

frame_width = 20                 # (float) length of entire horizontal shot
frame_width_units = 'in'         # (str) units frame_width is given in
fps = 30                         # (int) frames per second
resolution = (1200, 1600)        # (tuple) HxW in pixels

Create a parameter object and video dataset

metadata = clone_metadata(tracking_files, 
                          label_files = boris_files, 
                          frame_width = frame_width, 
                          fps = fps, 
                          frame_width_units = frame_width_units, 
                          resolution = resolution)

animal_renamer = {'adult': 'resident', 'juvenile':'intruder'}

dataset = VideosetDataFrame(metadata, animal_renamer=animal_renamer)

Now create features on this dataset

dataset.add_features(compute_dl_probability_features, 
                     featureset_name = '1dcnn', 
                     add_to_features = True)

dataset.add_features(compute_mars_features, 
                     featureset_name = 'MARS', 
                     add_to_features = True)

Now access a features table, labels, and groups for learning with dataset.features, dataset.labels, dataset.groups. From here it's easy to use some ML libraries to predict behavior. For example:

from sklearn.ensemble import ExtraTreesClassifier, RandomForestClassifier
from sklearn.model_selection import cross_val_predict
from sklearn.metrics import accuracy_score

model = RandomForestClassifier()
predictions = cross_val_predict(model, dataset.features, dataset.labels, dataset.groups)
score = accuracy_score(dataset.labels, predictions)

Features

  • Quickly generate a movie

Project details


Download files

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

Source Distribution

behaveml-0.2.9.tar.gz (12.8 MB view details)

Uploaded Source

Built Distribution

behaveml-0.2.9-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file behaveml-0.2.9.tar.gz.

File metadata

  • Download URL: behaveml-0.2.9.tar.gz
  • Upload date:
  • Size: 12.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for behaveml-0.2.9.tar.gz
Algorithm Hash digest
SHA256 4a9a555685e4638dacbd4e24413d10fc074c0a0e5fa96ad03c149e26bc3a5938
MD5 20e89f16afb4a5f7a9c45f818ac6d3d4
BLAKE2b-256 a415ed4ebae8c1e15ad7bf28448024f1cd569b65135fbd319a5a059403e7ce53

See more details on using hashes here.

File details

Details for the file behaveml-0.2.9-py3-none-any.whl.

File metadata

  • Download URL: behaveml-0.2.9-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/3.10.0 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

File hashes

Hashes for behaveml-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 6b3d60bdca5c2d92c05bf4ac75d09aec2fbee095ce12ef597fe7b043ab6d5890
MD5 716176bbf07bf40132538cebbca7c0ca
BLAKE2b-256 60be108e7b6e16f9b15c8d4183737130d5eac05324971f153647908b78fde68d

See more details on using hashes here.

Supported by

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