PWK: Proportion-weighted k-nearest neighbor

Description Usage Arguments Value References Examples

View source: R/PWK_method.r

Description

It is a nearest-neighbor classifier adapted for working over quantification problems. This method applies a weighting scheme, reducing the weight on neighbors from the majority class.

Usage

1
PWK(train, y, test, alpha=1, n_neighbors=10)

Arguments

train

a data.frame containing the training data.

y

a vector containing the target values.

test

a data.frame containing the test data.

alpha

a numeric value defining the proportion-weighted k-nearest neighbor algorithm as proposed by Barranquero et al., (2012). (Default: 1).

n_neighbors

a integer value defining the number of neighbors to use by default for nearest neighbor queries (Default: 10).

Value

A numeric vector containing the class distribution estimated from the test set.

References

Barranquero, J., González, P., Díez, J., & Del Coz, J. J. (2013). On the study of nearest neighbor algorithms for prevalence estimation in binary problems. Pattern Recognition, 46(2), 472-482.<doi.org/10.1016/j.patcog.2012.07.022>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
library(caret)
library(FNN)
cv <- createFolds(aeAegypti$class, 2)
tr <- aeAegypti[cv$Fold1,]
ts <- aeAegypti[cv$Fold2,]

# -- Getting a sample from ts with 80 positive and 20 negative instances --
ts_sample <- rbind(ts[sample(which(ts$class==1),80),],
                   ts[sample(which(ts$class==2),20),])
PWK(train=tr[,-which(names(tr)=="class")], y=tr[,"class"], test= ts[,-which(names(ts)=="class")])

mlquantify documentation built on Jan. 20, 2022, 5:07 p.m.