zamba

zamba.cli

zamba.models

zamba.models.manager

class zamba.models.manager.GetItemMeta[source]

Bases: enum.EnumMeta

Complicated override so that we can use hashing in ModelManager init.

class zamba.models.manager.ModelManager(model_path=PosixPath('.'), proba_threshold=None, output_class_names=False, tempdir=None, verbose=False, model_class='cnnensemble', model_kwargs={})[source]

Bases: object

Mediates loading, configuration, and logic of model calls.

Parameters:
  • model_path (str | Path) – path to model weights and architecture Required argument. Will be instantiated as Model object.
  • proba_threshold (float) – probability threshold for classification Defaults to None, in which case class probabilities are returned.
  • tempdir (str | Path) – path to temporary directory If specific temporary directory is to be used, its path is passed here. Defaults to None.
  • verbose (bool) – controls verbosity of prediction, training, and tuning methods Defaults to True in which case training, tuning or prediction progress will be logged.
  • model_class (str) – controls whether sample model class or production model class is used Defaults to “winning”. Must be “winning” or “sample”.
predict(data_path, save=False, pred_path=None)[source]
Parameters:
  • data_path (str | Path) – path to input data
  • pred_path (str | Path) – where predictions will be saved

Returns: DataFrame of predictions

train()[source]

Returns:

tune()[source]

Returns:

class zamba.models.manager.ModelName(string, model)[source]

Bases: enum.Enum

Allows easy control over which Model subclass to load. To add a new model class, add a line like NEW_MODEL = ('new_model', NewModelClass)

Args:
string (str) : string used to reference the model model model (Model) : model class to instantiate into manager
SAMPLE = ('sample', <class 'zamba.models.model.SampleModel'>)
WINNING = ('cnnensemble', <class 'zamba.models.cnnensemble_model.CnnEnsemble'>)

zamba.models.model

class zamba.models.model.Model(model_path=None, tempdir=None, verbose=False)[source]

Bases: object

Abstract class implementing required methods for any model in the api.

Parameters:
  • model_path (str | Path) – path to model files Converted to Path object in __init__. Defaults to None.
  • tempdir (str | Path) – path to temporary diretory Path to temporary directory, if used. Defaults to None.
model_path

str | Path – path to model files Converted to Path object in __init__. Defaults to None.

tempdir

str | Path – path to temporary diretory Path to temporary directory, if used. Defaults to None.

delete_tempdir

bool – whether to clean up tempdir Clean up tempdir if used.

finetune(X, y)[source]

Finetune the network for a different task by keeping the trained weights, replacing the top layer with one that outputs the new classes, and re-training for a few epochs to have the model output the new classes instead.

Parameters:
  • X
  • y

Returns:

fit()[source]

Use the same architecture, but train the weights from scratch using the provided X and y.

Parameters:
  • X – training inputs Numpy arrays probably
  • y – training labels Class labels

Returns:

predict(X)[source]
Parameters:X – Input to model.

Returns: DataFrame of class probabilities.

save_model()[source]

Save the model weights, checkpoints, to model_path.

Returns:

class zamba.models.model.SampleModel(model_path=None, tempdir=None, verbose=False)[source]

Bases: zamba.models.model.Model

Sample model for testing.

Parameters:
  • model_path
  • tempdir
load_data(data_path)[source]

SampleModel loads pickled data

Parameters:data_path

Returns:

predict(X)[source]
Parameters:X (list | numpy array) – data for test computation

Returns: DataFrame with two columns, added and multiplied.

save_model(path=None)[source]

Save the SampleModel.

If no path is passed, tries to use model_path attribute.

Parameters:path

Returns:

zamba.models.cnnensemble