cytopy.flow.cell_classifier.keras_classifier¶
This module contains the base class KerasCellClassifier for using deep learning methods, trained on some labeled FileGroup (has existing Populations), to predict single cell classifications.
Copyright 2020 Ross Burton
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Classes:
|
Use Keras deep learning models to predict the classification of single cell data. |
-
class
cytopy.flow.cell_classifier.keras_classifier.
KerasCellClassifier
(model: Optional[tensorflow.python.keras.engine.sequential.Sequential] = None, optimizer: Optional[str] = None, loss: Optional[str] = None, metrics: Optional[list] = None, **kwargs)¶ Use Keras deep learning models to predict the classification of single cell data. Training data should be provided in the form of a FileGroup with existing Populations. Supports multi-class and multi-label classification; if multi-label classification is chosen, the tree structure of training data is NOT conserved - all resulting populations will have the same parent population.
Note, this class assumes you use the Keras Sequential API. Objects can be constructed using a pre-built model, or the model designed through the parameters ‘optimizer’, ‘loss’ and ‘metrics, and then a model constructed using the ‘build_model’ method.
- Parameters
model (Sequential, optional) – Pre-compiled Keras Sequential model
optimizer (str, optional) – Provide if you intend to compile a model with the ‘build_model’ method. See https://keras.io/api/optimizers/ for optimizers
loss (str, optional) – Provide if you intend to compile a model with the ‘build_model’ method. See https://keras.io/api/losses/ for valid loss functions
metrics (list, optional) – Provide if you intend to compile a model with the ‘build_model’ method. See https://keras.io/api/metrics/ for valid metrics
features (list) – List of channels/markers to use as features in prediction
target_populations (list) – List of populations from training data to predict
multi_label (bool (default=False)) – If True, single cells can belong to more than one population. The tree structure of training data is NOT conserved - all resulting populations will have the same parent population.
logging_level (int (default=logging.INFO)) – Level to log events at
log (str, optional) – Path to log output to; if not given, will log to stdout
population_prefix (str (default=”CellClassifier_”)) – Prefix applied to populations generated
-
transformer
¶ Transformer object
- Type
-
class_weights
¶ Sample class weights; key is sample index, value is weight. Set by calling compute_class_weights.
- Type
dict
-
x
¶ Training feature space
- Type
Pandas.DataFrame
-
y
¶ Target labels
- Type
numpy.ndarray
-
logger
¶ - Type
logging.Logger
-
features
¶ - Type
list
-
target_populations
¶ - Type
list
Methods:
build_model
(layers, layer_params[, input_shape])If Sequential model is not constructed and provided at object construction, this method can be used to specify a sequential model to be built.
-
build_model
(layers: list, layer_params: list, input_shape: Optional[tuple] = None, **compile_kwargs)¶ If Sequential model is not constructed and provided at object construction, this method can be used to specify a sequential model to be built.
- Parameters
layers (list) – List of keras layer class names (see https://keras.io/api/layers/)
layer_params (list) – List of parameters to use when constructing layers (order must match layers)
input_shape (tuple, optional) – Shape of input data to first layer, if None, then passed as (N, ) where N is the number of features
compile_kwargs – Additional keyword arguments passed when calling compile
- Returns
- Return type
self