Description Usage Arguments Value References See Also Examples
Creates an efficient kernel 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 a derivative of arbitrary
order of the functional observations.
For kernel functions all kernels implemented in fda.usc
are available as well as custom kernel functions.
1 2 3 4 5 |
classes |
[ |
fdata |
[ |
grid |
[ |
h |
[numeric(1)] |
metric |
[ |
ker |
[numeric(1)] |
nderiv |
[ |
derived |
[ |
deriv.method |
[ |
custom.metric |
[ |
custom.ker |
[function(u)] |
... |
further arguments to and from other methods. Hand over additional arguments to
|
classiKernel
returns an object of class 'classiKernel'
.
This is a list containing at least the
following components:
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.
proc.fdata
the preprocessed data (missing values interpolated,
derived and evenly spaced). This data is this.fdataTransform(fdata)
.
See this.fdataTransform
for more details.
grid
numeric vector containing the grid on which fdata
is observed)
h
numeric value giving the bandwidth to be used in the kernel function.
ker
character encoding the kernel function to use.
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.
call
the original function call.
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.classiKernel
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 | # How to implement your own kernel function
data("ArrowHead")
classes = ArrowHead[,"target"]
set.seed(123)
train_inds = sample(1:nrow(ArrowHead), size = 0.8 * nrow(ArrowHead), replace = FALSE)
test_inds = (1:nrow(ArrowHead))[!(1:nrow(ArrowHead)) %in% train_inds]
ArrowHead = ArrowHead[,!colnames(ArrowHead) == "target"]
# custom kernel
myTriangularKernel = function(u) {
return((1 - abs(u)) * (abs(u) < 1))
}
# create the model
mod1 = classiKernel(classes = classes[train_inds], fdata = ArrowHead[train_inds,],
ker = "custom.ker", h = 2, custom.ker = myTriangularKernel)
# calculate the model predictions
pred1 = predict(mod1, newdata = ArrowHead[test_inds,], predict.type = "response")
# prediction accuracy
mean(pred1 == classes[test_inds])
# create another model using an existing kernel function
mod2 = classiKernel(classes = classes[train_inds], fdata = ArrowHead[train_inds,],
ker = "Ker.tri", h = 2)
# calculate the model predictions
pred2 = predict(mod1, newdata = ArrowHead[test_inds,], predict.type = "response")
# prediction accuracy
mean(pred2 == classes[test_inds])
## Not run:
# Parallelize across 2 CPU's
library(parallelMap)
parallelStartSocket(2L) # parallelStartMulticore for Linux
predict(mod1, 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.