NCM#
- class capymoa.ocl.strategy.NCM[source]#
Bases:
BatchClassifier
Nearest Class Mean (NCM).
NCM is a simple classifier that uses the mean of each class as a prototype. It calculates the distance from each input to the class means and assigns the class with the closest mean as the predicted class.
- __init__(
- schema: Schema,
- pre_processor: Module = nn.Identity(),
- num_features: int | None = None,
- device: device | str = torch.device('cpu'),
Initialize a NCM classifier head.
- Parameters:
schema – Describes the shape and type of the data.
pre_processor – A pre-processing module to apply to the input data, defaults to an identity module.
num_features – Number of features once pre-processed, defaults to the number of attributes in the schema.
device – Device to run the model on, defaults to CPU.
- batch_predict_proba(x: Tensor) Tensor [source]#
Predict the probabilities of the classes for a batch of instances.
- predict(instance: Instance) int | None [source]#
Predict the label of an instance.
The base implementation calls
predict_proba()
and returns the label with the highest probability.- Parameters:
instance – The instance to predict the label for.
- Returns:
The predicted label or
None
if the classifier is unable to make a prediction.
- predict_proba(
- instance: Instance,
Calls
batch_predict_proba()
with a batch of size 1.
- train(instance: LabeledInstance) None [source]#
Calls
batch_train()
with a batch of size 1.
- random_seed: int#
The random seed for reproducibility.
When implementing a classifier ensure random number generators are seeded.