Learn R Programming

TSdist (version 3.1)

OneNN: 1NN classification for a pair of train/test time series datasets.

Description

Given a specific distance measure, this function provides the 1NN classification values and the associated error for a specific train/test pair of time series databases.

Usage

OneNN(train, trainc, test, testc, distance, ...)

Arguments

train
Time series database saved in a numeric matrix, a list, an mts object, a zoo object or xts object.
trainc
Numerical vector which indicates the class of each of the series in the training set.
test
Time series database saved in a numeric matrix, a list, an mts object, a zoo object or xts object.
testc
Numerical vector which indicates the class of each of the series in the testing set.
distance
Distance measure to be used. It must be one of: "euclidean", "manhattan", "minkowski", "infnorm", "ccor", "sts", "dtw", "keogh_lb", "edr",
...
Additional parameters required by the chosen distance measure.

Value

  • classesNumerical vector providing the predicted class values for the series in the test set.
  • errorError obtained in the 1NN classification process.

Details

This function is useful to evaluate the performance of different distance measures in the task of classification of time series.

See Also

To calculate the distance matrices of time series databases the TSDatabaseDistances is used.

Examples

Run this code
# The example.database2 synthetic database is loaded
data(example.database2)

# Create train/test by dividing the dataset 70%-30%
set.seed(100)
trainindex <- sample(1:100, 70, replace=FALSE)
train <- example.database2[[1]][trainindex, ]
test <- example.database2[[1]][-trainindex, ]
trainclass <- example.database2[[2]][trainindex]
testclass <- example.database2[[2]][-trainindex]

# Apply the 1NN classifier for different distance measures

OneNN(train, trainclass, test, testclass, "euclidean")
OneNN(train, trainclass, test, testclass, "cid")
OneNN(train, trainclass, test, testclass, "pdc")

Run the code above in your browser using DataLab