mdx.behavior_learning.nn.behavior_learning module

class BehaviorLearning(config)

Bases: object

Module to facilitate deep learning on behavior data.

Parameters:

config (dict) – configuration for the module

behavior_learning = BehaviorLearning(config)
create_dataset(features, labels)

Creates and returns dataset from features and label data. Features are converted into tensors and reshaped to [-1, numPoints, 2] (training accepts data in this format). Can be conveniently called using the results of extract_features().

Parameters:
  • features (pandas.Dataframe) – features used for training

  • labels (pandas.Series_or_pandas.Dataframe) – corresponding labels

Returns:

dataset

Return type:

torch.utils.data.Dataset

dataset = behavior_learning.create_dataset(features, labels)
extract_features_and_labels(data)

Explodes the locations field, and retruns a dataframe with 2 * numPoints columns as the features dataframe. Each column holds data for a fixed lat or lon. Example - With the default value of numPoints this would return a dataframe with columns Lat0, Lon0, Lat1, Lon1 … Lat99, Lon99. Also returns the labels as a pandas.Series.

Parameters:

data (pandas.Dataframe) – pandas dataframe containing behavior data.

Returns:

returns a exploded dataframe as features and the corresponding labels

Return type:

(pandas.Dataframe, pandas.Series)

features, labels = behavior_learning.extract_features_and_labels(training_data)
instantiate_model(num_features, num_classes, min_tensor, max_tensor)

Instantiates and configures a deep learning model. Min_tensor and Max_tensor will be used for normalization.

Parameters:
  • num_features (int) – number of features in training data.

  • num_classes (int) – number of classes (unique y values)

  • min_tensor (torch.Tensor) – single dimension tensor of size 2 * numPoints (numPoints corresponds to number of points behavior). Will be used as the lower bound during normalization.

  • max_tensor (torch.Tensor) – single dimension tensor of size 2 * numPoints (numPoints corresponds to number of points behavior). Will be used as the upper bound during normalization.

Returns:

configured model.

Return type:

nn.Module

model = behavior_learning.instantiate_model(num_features, num_classes, min_tensor, max_tensor)
train_and_export_model(training_data)

Outputs a deep learning model trained on the behavior data. Behavior data’s location field is used for features. Training parameters are taken from the config file. Internally uses train_model().

Parameters:

data (pandas.Dataframe) – behavior data to train on. Internally divided into training, testing and validation sets.

Returns:

trained model and training and validation stats as a python dict.

Return type:

(nn.Module, dict)

model, training_results = train_and_export_model(labelled_data)
train_model(dataset, model)

Trains the provided model on dataset. For training, dataset is split into training and validation sets. Training parameters are set in the config file are used.

Parameters:
  • dataset (Dataset) – dataset for training and validation. Dataset __get__item()

  • model (nn.Module) – model to be used for training.

Returns:

returns the trained model, along with the training stats

Return type:

(nn.Module, dict)

model, training_results = train_model(df_behavior_data)
update_config(new_config)

Updates the config of the module with the user provided config.

Parameters:

new_config (dict) – new config for update.

Returns:

none

behavior_learning.update_config(new_config)
validate_learning_config()