Skip to main content

Configuring Distance Metric

Configuring Distance Metric for KNN

Function Signature

def config_distance(self, distance):

Parameters

  • distance: The name of the distance metric to be configured for the KNN instance.

Return Value

This function does not return anything. It modifies the KNN instance.

Description

The config_distance function sets the distance metric for the KNN instance.

The valid distance metrics that can be passed to this function are:

  • "hamming distance"
  • "minkowski distance"
  • "manhattan distance"
  • "euclidean distance"

Examples

from deeprai.models import KNN

# Create an instance of the classifier
classifier = KNN()

# Configure the distance metric to be used
classifier.config_distance("euclidean distance")