我的目标是将关联规则应用于文本挖掘。
我有这个字符串样本:
sample.word = c("abstracting","abstracting workflow","access control","access information","access methods","access patterns","access permissions","access to government information","accountability","acetamides")
比我制作一个所有值都为 0 的矩阵
incidence.matrix_sample <- matrix(0, nrow=5, ncol=length(sample.word))
我将字符串添加为矩阵列
colnames(incidence.matrix_sample) <- sample.word
现在我使用 pmatch 函数在文档中出现的术语列中输入 1 个值(documents.ids[[i]] 是一个带有文档 id 的向量)
for(i in 1:(dim(incidence.matrix_sample)[1]))
{
incidence.matrix_sample[i, pmatch(documents.ids[[i]], sample.word)] <- 1
}
我尝试继续并将我的矩阵首先转换为 itemMatrix,然后转换为事务(使用 as(my.matrix, "transactions") 函数)但是当我尝试检查规则时,我得到了同样的错误:
incidence.matrix_sample <- as(incidence.matrix_sample, "itemMatrix")
incidence.matrix_sample <- as(incidence.matrix_sample, "transactions")
inspect(incidence.matrix_sample)
结果是:
Errore in UseMethod("inspect", x) :
no applicable method for 'inspect' applied to an object of class "c('matrix', 'double', 'numeric')"
以及使用 apriori 函数对发病率.matrix_sample 的相同问题
Errore in UseMethod("inspect", x) :
no applicable method for 'inspect' applied to an object of class "c('rules', 'associations')"
是我试图了解问题出在哪里的日子..有人可以帮助我吗?