我正在尝试为机器学习准备数据集。在此过程中,我想删除(停止)很少出现的单词(通常与错误的 OCR 读数有关)。目前,我有一个包含大约 1 个要删除的 mio 单词的单词列表。
但是,使用此设置处理我的数据集需要很长时间。
library(stringi)
#generate the stopword list
b <- stri_rand_strings(1000000, 4, pattern = "[A-Za-z0-9]")
#remove stopstopwords form the dataset
system.time({
a <- stri_rand_strings(10, 4, pattern = "[A-Za-z0-9]")
c <- a[!(a %in% b)]
c
})
user system elapsed
0.14 0.00 0.14
似乎'a %in% b' 不是(远离)O(N)。在整个数据集上运行它是不可行的,因为该过程不会在几个小时内完成。
有没有更有效的方法来比较 R 中的两个向量?
我怀疑它的查找速度应该非常快。我在 C# 中使用 Dictionary 进行了测试,该测试在几分钟内完成。