Learn R Programming

MSclassifR (version 0.4.0)

fast_find_neighbors: Function finding k Nearest Neighbors for each row of a matrix

Description

This function finds the k nearest neighbors for each row in a matrix using the specified distance metric. Distance metrics available are "p-norm", "Chebyshev", "Canberra", "Overlap", "HEOM" (Heterogeneous Euclidean-Overlap Metric), "HVDM" (Heterogeneous Value Difference Metric). See the calculate_distance function of our package for more details on the distances.

Usage

fast_find_neighbors(data, nominal_indices, p_code, k)

Value

A matrix where each row contains the indices of the k nearest neighbors for the corresponding example.

Arguments

data

Matrix where the k nearest neighbors for each row are searched.

nominal_indices

Vector of column indices indicating which features are categorical (nominal) variables. This is crucial for proper distance calculation as nominal and numeric features require different handling. For example, if columns 2 and 5 contain categorical variables, nominal_indices should be c(2, 5). See calculate_distance function.

p_code

Numeric code representing the distance metric to use:

  • p >= 1: p-norm

  • p = 0: Chebyshev

  • p = -1: Canberra

  • p = -2: Overlap (nominal attributes only)

  • p = -3: HEOM (Heterogeneous Euclidean-Overlap Metric)

  • p = -4: HVDM (Heterogeneous Value Difference Metric)

k

Number of nearest neighbors to find.

See Also

calculate_distance