Learn R Programming

jmotif (version 1.3.2)

cosine_sim: Computes the cosine distance value between a bag of words and a set of TF-IDF weight vectors.

Description

Computes the cosine distance value between a bag of words and a set of TF-IDF weight vectors.

Usage

cosine_sim(data)

Arguments

data

the list containing a word-bag and the TF-IDF object.

References

Senin Pavel and Malinchik Sergey, SAX-VSM: Interpretable Time Series Classification Using SAX and Vector Space Model. Data Mining (ICDM), 2013 IEEE 13th International Conference on, pp.1175,1180, 7-10 Dec. 2013.

Salton, G., Wong, A., Yang., C., A vector space model for automatic indexing. Commun. ACM 18, 11, 613-620, 1975.

Examples

Run this code
data(CBF)
w <- 60; p <- 6; a <- 6
train <- CBF[["data_train"]]
bag1 <- manyseries_to_wordbag(train[CBF[["labels_train"]] == 1, ], w, p, a, "exact", 0.01)
bag2 <- manyseries_to_wordbag(train[CBF[["labels_train"]] == 2, ], w, p, a, "exact", 0.01)
bag3 <- manyseries_to_wordbag(train[CBF[["labels_train"]] == 3, ], w, p, a, "exact", 0.01)
tfidf <- bags_to_tfidf(list(cylinder = bag1, bell = bag2, funnel = bag3))
sample <- CBF[["data_test"]][CBF[["labels_test"]] == 3, ][1, ]
bag <- series_to_wordbag(sample, w, p, a, "exact", 0.01)
cosine_sim(list(bag = bag, tfidf = tfidf))

Run the code above in your browser using DataLab