bagofpatterns_knn: Bag of Patterns (K-Nearest Neighbours)

View source: R/bag_of_patterns_knn.R

bagofpatterns_knnR Documentation

Bag of Patterns (K-Nearest Neighbours)

Description

Fit a Bag of Patterns Model with KNN

Usage

bagofpatterns_knn(
  data,
  target = "target",
  window_size = 0.2,
  sparse_windows = FALSE,
  normalize = FALSE,
  alphabet_size = 4,
  word_size = 8,
  breakpoints = "quantiles",
  word_weighting = tm::weightTf,
  maximum_sparsity = NA,
  verbose = TRUE,
  k = 3,
  algorithm = "kd_tree",
  prob = FALSE
)

Arguments

data

a data frame where each row is a time series, along with a column for class

target

the name of the column where the class of each row is stored

window_size

The size of the sliding windows as applied to the time series, either as a fraction of the length or an integer of precise length.

sparse_windows

a logical, indicating whether sqrt(m) random windows should be taken instead of all

normalize

a logical, indicating whether each window should be z-normalized (⁠(x - mean(x)/sd(x)⁠)

alphabet_size

the number of distinct letters to use in the compressed SAX representation

word_size

the size of the 'words' generated out of the alphabet by SAX

breakpoints

the method used to assign letters (see seewave::SAX)

word_weighting

The weighting function for the DTM/TDM (default is term-frequency, effectively unweighted)

maximum_sparsity

A optional numeric for the maximal allowed sparsity in the range from bigger zero to smaller one.

verbose

whether to print the progress of model creation.

...

arguments to be passed to FNN:knn

Details

This function fits a bag of patterns model by using Symbolic Aggregate eXpressions (SAX) to convert a data frame of time series into a count table of 'words' as generated by SAX generated by sliding windows over the series. New examples are then fit by finding nearest neighbor examples with the converted training data.

Examples

data("FaceAll_TRAIN")
model <- bagofpatterns_knn(FaceAll_TRAIN, window_size = .9, alphabet_size = 2, word_size = 2)

mattsq/bagofpatternsr documentation built on April 5, 2025, 3:05 a.m.