Constructing a k-nearest neighbors classifier