Skip to main content

Instant classifier


Instant Classifier Function

Function Signature

def instant_classifier(self, x_vals, y_vals, query_point, p=3, k=2):

Parameters

  • x_vals: The input data points.

  • y_vals (must be converted to int32): The labels corresponding to the input data points.

  • query_point: The point for which classification is to be determined.

  • p (int, default=3): The power parameter for the Minkowski distance metric.

  • k (int, default=2): The number of nearest neighbors to consider for classification.

Return Value

Returns the classification result for the query_point based on the k nearest neighbors in the x_vals dataset.

Description

The instant_classifier function classifies a given query_point based on the k nearest neighbors in the x_vals dataset.  The labels of the k nearest neighbors are then used to determine the classification of the query_point.

Examples

from deeprai.models import KNN

# Sample data
x_vals = [[1, 2], [2, 3], [3, 4]]
y_vals = [0, 1, 0]
query_point = [2, 2]

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

# Classify the query_point
result = classifier.instant_classifier(x_vals, y_vals, query_point, p=3, k=2)
print(result) # This will print the classification result for the query_point

Note: Ensure that y_vals is converted to int32 before passing it to the function.