k-Nearest Neighbour Regression
$k$-nearest neighbour regression that can return the average value for the neighbours.
knnreg(x, ...) ## Default S3 method: knnreg(x, ...) ## S3 method for class 'formula' knnreg(formula, data, subset, na.action, k = 5, ...) ## S3 method for class 'matrix' knnreg(x, y, k = 5, ...) ## S3 method for class 'data.frame' knnreg(x, y, k = 5, ...) ## S3 method for class 'knnreg' print(x, ...) knnregTrain(train, test, y, k = 5, use.all = TRUE)
x |
a matrix or data frame of training set predictors. |
... |
additional parameters to pass to |
formula |
a formula of the form |
data |
optional data frame containing the variables in the model formula. |
subset |
optional vector specifying a subset of observations to be used. |
na.action |
function which indicates what should happen when the data
contain |
k |
number of neighbours considered. |
y |
a numeric vector of outcomes. |
train |
matrix or data frame of training set cases. |
test |
matrix or data frame of test set cases. A vector will be interpreted as a row vector for a single case. |
use.all |
controls handling of ties. If true, all distances equal to
the |
An object of class knnreg
. See predict.knnreg
.
data(BloodBrain) inTrain <- createDataPartition(logBBB, p = .8)[[1]] trainX <- bbbDescr[inTrain,] trainY <- logBBB[inTrain] testX <- bbbDescr[-inTrain,] testY <- logBBB[-inTrain] fit <- knnreg(trainX, trainY, k = 3) plot(testY, predict(fit, testX))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.