kncount: Counting the number of each class in K nearest neighbor

Description Usage Arguments Details Value Author(s) Examples

View source: R/kncount.R

Description

The function to count how many neighbor of each instance belong to each class.

Usage

1
kncount(knidex, classArray)

Arguments

knidex

The matrix of K nearest neighbor of dataset

classArray

The index of last instance of the first class in the dataset or the vector containing indices of last instances of each class.

Details

The dataset is expected to be sorted as all m1 instances in the first class are in the first m1 instances of the dataset following with all m2 instances in the next m2 instances etc. before performing k-nearest neighbor with the knearest function.

Value

The matrix with the number of columns equal to the number of classes. Each a[i][j] represents the number of K-nearest neighbors of i th instance belonging to the class j th

Author(s)

Wacharasak Siriseriwan <wacharasak.s@gmail.com>

Examples

1
2
3
4
5
6
	 D = sample_generator(1000,ratio = 0.8)
	 P = D[D[,3]=="p",]
	 N = D[D[,3]=="n",]
	 D_arr=rbind(P,N)
     knear=knearest(D_arr[,-3],P[,-3],5)
	 kncount_result = kncount(knear,nrow(P))

smotefamily documentation built on May 30, 2019, 9:01 a.m.