具有 800K 文档的 R 文本分类
R Text Classification with 800K documents
我必须对包含 800K 文本的文本分类做一些工作。我一直在尝试 运行 我在下面找到的一个实际例子 link:
http://garonfolo.dk/herbert/2015/05/r-text-classification-using-a-k-nearest-neighbour-model/
一切顺利,直到我收到以下说明:
# Transform dtm to matrix to data frame - df is easier to work with
mat.df <- as.data.frame(data.matrix(dtm), stringsAsfactors = FALSE)
运行 几个小时后,我收到一条错误消息:
Error: cannot allocate vector of size 583.9 Gb
In addition: Warning messages:
1: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
2: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
3: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
4: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
有没有办法克服这个错误?
是否可以将 data.matrix(dtm) 拆分为 运行 块中的作业,然后以某种方式合并它们?还是以另一种方式或 Python?
来解决这个问题更好?
谢谢
在 as.data.frame()
调用之前,输入这行代码:
dtm <- removeSparseTerms(dtm, sparse=0.9)
。
参数sparse=...
是一个介于0和1之间的数字。它与您要保留的文档数量成正比。以上,是不是90%。通常,您会通过反复试验找到 correct/optimal 值。在您的情况下,您可能会得到一个奇怪的数字,例如 0.79333。取决于你想做什么。
removeSparseTerms()
删除 Terms,但保持较小的结果矩阵中的文档数量不变。因此,您将从 12165735 * 800000 元素矩阵变为 476 * 800000 矩阵。现在可以在您的计算机上处理此问题。
如果没有,请在您的大矩阵中尝试一个巧妙的按列拆分-应用-组合技巧。
我必须对包含 800K 文本的文本分类做一些工作。我一直在尝试 运行 我在下面找到的一个实际例子 link:
http://garonfolo.dk/herbert/2015/05/r-text-classification-using-a-k-nearest-neighbour-model/
一切顺利,直到我收到以下说明:
# Transform dtm to matrix to data frame - df is easier to work with
mat.df <- as.data.frame(data.matrix(dtm), stringsAsfactors = FALSE)
运行 几个小时后,我收到一条错误消息:
Error: cannot allocate vector of size 583.9 Gb
In addition: Warning messages:
1: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
2: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
3: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
4: In vector(typeof(x$v), prod(nr, nc)) :
Reached total allocation of 8076Mb: see help(memory.size)
有没有办法克服这个错误?
是否可以将 data.matrix(dtm) 拆分为 运行 块中的作业,然后以某种方式合并它们?还是以另一种方式或 Python?
来解决这个问题更好?谢谢
在 as.data.frame()
调用之前,输入这行代码:
dtm <- removeSparseTerms(dtm, sparse=0.9)
。
参数sparse=...
是一个介于0和1之间的数字。它与您要保留的文档数量成正比。以上,是不是90%。通常,您会通过反复试验找到 correct/optimal 值。在您的情况下,您可能会得到一个奇怪的数字,例如 0.79333。取决于你想做什么。
removeSparseTerms()
删除 Terms,但保持较小的结果矩阵中的文档数量不变。因此,您将从 12165735 * 800000 元素矩阵变为 476 * 800000 矩阵。现在可以在您的计算机上处理此问题。
如果没有,请在您的大矩阵中尝试一个巧妙的按列拆分-应用-组合技巧。