scvi.core.trainers.ClassifierTrainer

class scvi.core.trainers.ClassifierTrainer(*args, train_size=0.9, test_size=None, sampling_model=None, sampling_zl=False, use_cuda=True, **kwargs)[source]

Class for training a classifier either on the raw data or on top of the latent space of another model.

Parameters
model

A model instance from class VAE, VAEC, SCANVI

gene_dataset

A gene_dataset instance like CortexDataset()

train_size

The train size, a float between 0 and 1 representing proportion of dataset to use for training to use Default: 0.9.

test_size

The test size, a float between 0 and 1 representing proportion of dataset to use for testing to use Default: None.

sampling_model

Model with z_encoder with which to first transform data.

sampling_zl

Transform data with sampling_model z_encoder and l_encoder and concat.

**kwargs

Other keywords arguments from the general Trainer class.

Examples

>>> gene_dataset = CortexDataset()
>>> vae = VAE(gene_dataset.nb_genes, n_batch=gene_dataset.n_batches * False,
... n_labels=gene_dataset.n_labels)
>>> classifier = Classifier(vae.n_latent, n_labels=cortex_dataset.n_labels)
>>> trainer = ClassifierTrainer(classifier, gene_dataset, sampling_model=vae, train_size=0.5)
>>> trainer.train(n_epochs=20, lr=1e-3)
>>> trainer.test_set.accuracy()

Attributes

default_metrics_to_monitor

scvi_data_loaders_loop

Methods

check_training_status()

Checks if loss is admissible.

compute_metrics()

create_scvi_dl([model, adata, shuffle, …])

data_loaders_loop()

Returns an zipped iterable corresponding to loss signature.

loss(tensors_labelled)

on_epoch_begin()

on_epoch_end()

on_iteration_begin()

on_iteration_end()

on_training_begin()

on_training_end()

on_training_loop(tensors_dict)

register_data_loader(name, value)

train([n_epochs, lr, eps, params])

train_test_validation([model, adata, …])

Creates data loaders train_set, test_set, validation_set.

training_extras_end()

Place to put extra models in eval mode, etc.

training_extras_init(**extras_kwargs)

Other necessary models to simultaneously train.