scQUEST.classifier module
Summary
Classes:
Classifier to classify a cell as epithelial or non-epithelial cell. |
|
Reference
- class DefaultCLF(n_in, hidden=(20,), n_out=2, bias=True, activation=ReLU(), activation_last=Softmax(dim=1), seed=None)[source]
Bases:
torch.nn.modules.module.Module
- __init__(n_in, hidden=(20,), n_out=2, bias=True, activation=ReLU(), activation_last=Softmax(dim=1), seed=None)[source]
Initializes internal Module state, shared by both nn.Module and ScriptModule.
- forward(x)[source]
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- __doc__ = None
- __module__ = 'scQUEST.classifier'
- class ClfLitModule(*args, **kwargs)[source]
Bases:
scQUEST.utils.LitModule
- forward(x)[source]
Same as
torch.nn.Module.forward()
.- Parameters
*args – Whatever you decide to pass into the forward method.
**kwargs – Keyword arguments are also possible.
- Return type
- Returns
Your model’s output
- __doc__ = None
- __module__ = 'scQUEST.classifier'
- class Classifier(n_in=None, model=None, loss_fn=None, metrics=None, seed=None)[source]
Bases:
scQUEST.utils.Estimator
Classifier to classify a cell as epithelial or non-epithelial cell. Classifier uses a shallow neural network to discriminate between epithelial and non-epithelial cells. To fit the classifier a pre-annotated sample is needed.
- Parameters
n_in – number of features
model – Model used to train estimator
torch.Module
orpytorch_lightning.Module
loss_fn – Loss function used for optimization
metrics – Metrics tracked during test time
- estimator = 'classifier'
- __init__(n_in=None, model=None, loss_fn=None, metrics=None, seed=None)[source]
Base estimator class
- Parameters
n_in – number of feature for estimator
model – Model used to train estimator
torch.Module
orpytorch_lightning.Module
loss_fn – Loss function used for optimization
metrics – Metrics tracked during test time
seed – Seed for model weight initialisation
- fit(ad=None, target=None, layer=None, datamodule=None, max_epochs=100, callbacks=None, seed=None, **kwargs)[source]
Fit the estimator on annotated data. Expression profiles in ad.layers[layer] are used to predict the phenotype given in ad.obs[target]. By default the given data is randomly split 90/10 in training and test set. If you wish to customize training provide a datamodule with the given train/validation/test splits.
- Parameters
ad (
Optional
[AnnData
]) – AnnData object with annotated cell types (given by the target parameter)target (
Optional
[str
]) – numerical column in AnnData.obs that should be used as target variable. The target needs to be numerically encoded \([0,C)\) where \(C\) is the number of classes.layer (
Optional
[str
]) – layer in ad.layers to use instead of ad.Xdatamodule (
Optional
[LightningDataModule
]) – pytorch lightning data module with custom configurations of train, val and test splitsmax_epochs (
int
) – maximum epochs for which the model is trainedcallbacks (
Optional
[list
]) – additional pytorch_lightning callbacks
- Return type
- Returns
None
- predict(ad, layer=None, inplace=True)[source]
Predict phenotype class. Uses the trained classifier to predict the phenotype of a given cell expression profile. The result is stored in ad.obs[‘clf_{TARGET_NAME}].
- __doc__ = 'Classifier to classify a cell as epithelial or non-epithelial cell. Classifier uses a shallow neural network to discriminate\n between epithelial and non-epithelial cells. To fit the classifier a pre-annotated sample is needed.\n\n Args:\n n_in: number of features\n model: Model used to train estimator :class:`.torch.Module` or :class:`.pytorch_lightning.Module`\n loss_fn: Loss function used for optimization\n metrics: Metrics tracked during test time\n '
- __module__ = 'scQUEST.classifier'