topicmodels::LDA
.
代码中有一个检查,要求所有值都是整数值。这意味着不允许值为0.001。见下例:
m_replaced_zero <- matrix(c(1, 1, 0.001, 0), nrow = 2)
LDA(m_replaced_zero)
Error in !all.equal(x$v, as.integer(x$v)) : invalid argument type
m_zero_row <- matrix(c(1, 0, 1, 0), nrow = 2)
[,1] [,2]
[1,] 1 1
[2,] 0 0
LDA(m_zero_row)
Error in LDA(m_zero_row) :
Each row of the input matrix needs to contain at least one non-zero entry
但是,如果要替换documenttermmatrix中的稀疏项,则首先需要将其转换为矩阵,然后替换0。
data("AssociatedPress")
m <- as.matrix(AssociatedPress)
m[m==0] <- 0.001