【发布时间】:2020-12-21 23:55:55
【问题描述】:
情况就是这样,一开始的解决方案似乎很简单,但结果却比我预期的要复杂。
我有一个包含三列的 R 数据框:一个 ID、一个包含文本(评论)的列,以及一个包含我想根据文本预测的数值的列。
我已经对文本列进行了一些预处理,所以它没有标点符号,小写,并且准备好被标记化并变成一个矩阵,这样我就可以在它上面训练一个模型。问题是我不知道如何从该文本中删除停用词。
这就是我想用 text2vec 包做的事情。一开始我打算在这个块之前删除停用词。但任何地方都可以。
library(text2vec)
test_data <- data.frame(review_id=c(1,2,3),
review=c('is a masterpiece a work of art',
'sporting some of the best writing and voice work',
'better in every possible way when compared'),
score=c(90, 100, 100))
tokens <- word_tokenizer(test_data$review)
document_term_matrix <- create_dtm(itoken(tokens), hash_vectorizer())
model_tfidf <- TfIdf$new()
document_term_matrix <- model_tfidf$fit_transform(document_term_matrix)
document_term_matrix <- as.matrix(document_term_matrix)
我希望评论栏是这样的:
review=c('masterpiec work art',
'sporting best writing voice work',
'better possible way compared')
【问题讨论】:
-
请向我们展示一些数据,创建一个great reproducible example 并举例说明您想要的输出。
标签: r text-mining