predict.knn: Predict k-nearest neighbour output

View source: R/SOptim_ClassificationFunctions.R

predict.knnR Documentation

Predict k-nearest neighbour output

Description

An auxiliary function used to predict the probabilistic outcome from the knn classifier for single or multi-class problems.

Usage

## S3 method for class 'knn'
predict(
  object,
  type = "response",
  newdata = NULL,
  traindata = NULL,
  cl = NULL,
  k = NULL,
  balanceTrainData = FALSE,
  balanceMethod = "ubOver",
  ...
)

Arguments

object

An object generated from knn function.

type

Type of response generated, if "prob" the probabilistic output for all classes will be returned. If "response" then the class labels are returned.

newdata

A dataset used to predict the class labels.

traindata

Train data used to calibrate the knn classifier.

cl

Factor of true classifications of training set.

k

Number of neighbours considered.

balanceTrainData

Defines if data balancing is to be used (only available for single-class problems; default: TRUE).

balanceMethod

A character string used to set the data balancing method. Available methods are based on under-sampling "ubUnder" or over-sampling "ubOver" the target class.

...

Additional arguments passed to knn.

Value

A matrix object with knn output.


joaofgoncalves/SegOptim documentation built on Feb. 5, 2024, 11:10 p.m.