File: knnreg.Rd

package info (click to toggle)
r-cran-caret 7.0-1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,036 kB
  • sloc: ansic: 210; sh: 10; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,534 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/knnreg.R
\name{knnreg}
\alias{knnreg}
\alias{knnregTrain}
\alias{knnreg.formula}
\alias{knnreg.default}
\alias{knnreg.matrix}
\alias{knnreg.data.frame}
\alias{print.knnreg}
\title{k-Nearest Neighbour Regression}
\usage{
knnreg(x, ...)

\method{knnreg}{default}(x, ...)

\method{knnreg}{formula}(formula, data, subset, na.action, k = 5, ...)

\method{knnreg}{matrix}(x, y, k = 5, ...)

\method{knnreg}{data.frame}(x, y, k = 5, ...)

\method{print}{knnreg}(x, ...)

knnregTrain(train, test, y, k = 5, use.all = TRUE)
}
\arguments{
\item{x}{a matrix or data frame of training set predictors.}

\item{...}{additional parameters to pass to \code{knnregTrain}.}

\item{formula}{a formula of the form \code{lhs ~ rhs} where \code{lhs} is
the response variable and \code{rhs} a set of predictors.}

\item{data}{optional data frame containing the variables in the model
formula.}

\item{subset}{optional vector specifying a subset of observations to be
used.}

\item{na.action}{function which indicates what should happen when the data
contain \code{NA}s.}

\item{k}{number of neighbours considered.}

\item{y}{a numeric vector of outcomes.}

\item{train}{matrix or data frame of training set cases.}

\item{test}{matrix or data frame of test set cases. A vector will be
interpreted as a row vector for a single case.}

\item{use.all}{controls handling of ties. If true, all distances equal to
the \code{k}th largest are included. If false, a random selection of
distances equal to the \code{k}th is chosen to use exactly \code{k}
neighbours.}
}
\value{
An object of class \code{knnreg}. See \code{\link{predict.knnreg}}.
}
\description{
$k$-nearest neighbour regression that can return the average value for the
neighbours.
}
\details{
\code{knnreg} is similar to \code{\link[ipred]{ipredknn}} and
\code{knnregTrain} is a modification of \code{\link[class]{knn}}. The
underlying C code from the \code{class} package has been modified to return
average outcome.
}
\examples{

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))

}
\author{
\code{\link[class]{knn}} by W. N. Venables and B. D. Ripley and
\code{\link[ipred]{ipredknn}} by Torsten.Hothorn
<Torsten.Hothorn@rzmail.uni-erlangen.de>, modifications by Max Kuhn and
Chris Keefer
}
\keyword{multivariate}