Description Usage Arguments Value References See Also Examples
Creates an efficient k nearest neighbor estimator for functional data
classification. Currently supported distance measures are all metrics
implemented in dist
and all semimetrics suggested in Fuchs et al. (2015).
Additionally, all (semi)metrics can be used on an arbitrary order of derivation.
1 2 3 4 
classes 
[ 
fdata 
[ 
grid 
[ 
knn 
[ 
metric 
[ 
nderiv 
[ 
derived 
[ 
deriv.method 
[ 
custom.metric 
[ 
... 
further arguments to and from other methods. Hand over additional arguments to

classiKnn
returns an object of class "classiKnn"
.
This is a list containing at least the
following components:
call
the original function call.
classes
a factor of length nrow(fdata) coding the response of the training data set.
fdata
the raw functional data as a matrix with the individual observations as rows.
grid
numeric vector containing the grid on which fdata
is observed)
proc.fdata
the preprocessed data (missing values interpolated,
derived and evenly spaced). This data is this.fdataTransform(fdata)
.
See this.fdataTransform
for more details.
knn
integer coding the number of nearest neighbors used in the k nearest neighbor classification algorithm.
metric
character string coding the distance metric to be used
in computeDistMat
.
nderiv
integer giving the order of derivation that is applied to fdata before computing the distances between the observations.
this.fdataTransform
preprocessing function taking new data as
a matrix. It is used to transform fdata
into proc.fdata
and
is required to preprocess new data in order to predict it. This function
ensures, that preprocessing (derivation, respacing and interpolation of
missing values) is done in the exact same way for the original
training data set and future (test) data sets.
Fuchs, K., J. Gertheiss, and G. Tutz (2015): Nearest neighbor ensembles for functional data with interpretable feature selection. Chemometrics and Intelligent Laboratory Systems 146, 186  197.
predict.classiKnn
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  # Classification of the Phoneme data
data(Phoneme)
classes = Phoneme[,"target"]
set.seed(123)
# Use 80% of data as training set and 20% as test set
train_inds = sample(1:nrow(Phoneme), size = 0.8 * nrow(Phoneme), replace = FALSE)
test_inds = (1:nrow(Phoneme))[!(1:nrow(Phoneme)) %in% train_inds]
# create functional data as matrix with observations as rows
fdata = Phoneme[,!colnames(Phoneme) == "target"]
# create k = 3 nearest neighbors classifier with L2 distance (default) of the
# first order derivative of the data
mod = classiKnn(classes = classes[train_inds], fdata = fdata[train_inds,],
nderiv = 1L, knn = 3L)
# predict the model for the test set
pred = predict(mod, newdata = fdata[test_inds,], predict.type = "prob")
## Not run:
# Parallelize across 2 CPU's
library(parallelMap)
parallelStartSocket(cpus = 2L) # parallelStartMulticore(cpus = 2L) for Linux
predict(mod, newdata = fdata[test_inds,], predict.type = "prob", parallel = TRUE, batches = 2L)
parallelStop()
## End(Not run)

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.