object

nearest_centroid

Nearest Centroid classifier with multiple distance metrics. Learns from a dataset object implementing the dataset_protocol protocol and returns a classifier term that can be used for prediction and exported as predicate clauses.

Availability:
logtalk_load(nearest_centroid(loader))
Author: Paulo Moura
Version: 1:0:0
Date: 2026-02-20
Compilation flags:
static, context_switching_calls
Implements:
Imports:
public options
Uses:
Remarks:
  • Algorithm: Assign to an instance the the class of the training samples whose mean (centroid) is closest to the instance.

  • Distance metrics: Supports Euclidean, Manhattan, and cosine distance metrics.

  • Feature types: Automatically handles numeric and categorical features.

  • Classifier representation: The learned classifier is represented by default as a nc_classifier(AttributeNames, FeatureTypes, Centroids) term.

Public predicates

predict/4

Predicts the class label for a new instance using the learned classifier and the given options. The instance is a list of Attribute-Value pairs.

Compilation flags:
static
Template:
predict(Classifier,Instance,Class,Options)
Mode and number of proofs:
predict(+compound,+list,-atom,+list(compound)) - one

predict_probabilities/3

Predicts class probabilities for a new instance using the learned classifier and default options. Returns a list of Class-Probability pairs. The instance is a list of Attribute-Value pairs.

Compilation flags:
static
Template:
predict_probabilities(Classifier,Instance,Probabilities)
Mode and number of proofs:
predict_probabilities(+compound,+list,-list) - one

predict_probabilities/4

Predicts class probabilities for a new instance using the learned classifier and the given options. Returns a list of Class-Probability pairs. The instance is a list of Attribute-Value pairs.

Compilation flags:
static
Template:
predict_probabilities(Classifier,Instance,Probabilities,Options)
Mode and number of proofs:
predict_probabilities(+compound,+list,-list,+list(compound)) - one

Protected predicates

(no local declarations; see entity ancestors if any)

Private predicates

(no local declarations; see entity ancestors if any)

Operators

(none)