smotefamily (version 1.3.1)

knearest: The function to find n_clust nearest neighbors of each instance, always removing the index of that instance if it is reported.

Description

The function will find n_clust nearest neighbors of each instance using Fast nearest neighbors (through KD-tree method) but will correct the result if it reports the index of that instance as its neighbors.

Usage

knearest(D, P, n_clust)

Value

The index matrix of K nearest neighbour of each instance

Arguments

D

a query data matrix.

P

an input data matrix

n_clust

the maximum number of nearest neighbors to search

Author

Wacharasak Siriseriwan <wacharasak.s@gmail.com>

Details

This function will perform K-nearest neighbor of instances in P on instances in P based on FNN. Then, it will verify if one of neighbors of each instance is itself then removes if it is.

Examples

Run this code
	data_example = sample_generator(10000,ratio = 0.80)
	P = data_example[data_example[,3]=="p",-3]
	N = data_example[data_example[,3]=="n",-3]
	D = rbind(P,N)
	knear = knearest(D,P,n_clust = 5)

Run the code above in your browser using DataLab