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.
fast_find_neighbors(data, nominal_indices, p_code, k)
A matrix where each row contains the indices of the k nearest neighbors for the corresponding example.
Matrix where the k nearest neighbors for each row are searched.
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.
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)
Number of nearest neighbors to find.
calculate_distance