我正在对银行客户关于抵押贷款的评论进行一些文本分析,我发现了一些我确实理解的事情。
1) 在不应用词干提取和检查 TDM 维度的情况下清理数据后,术语数 (2173) 小于文档数 (2373)(这是在删除停用词和将 TDM 设为 1-gram 之前)。
2) 另外,我想检查对 TDM 进行二元标记的 2 词频率 (rowSums(Matrix))。问题是,例如,我得到的重复次数最多的结果是 2 个单词“Proble Miss”。由于这个分组已经很奇怪了,我去了数据集“Control + F”,试图找到,但我找不到。问题:似乎代码有些如何阻止这些词,这怎么可能?(从前 25 个双字中,这一个是唯一一个似乎被阻止的)。这不应该只创建始终在一起的二元组吗?
{file_cleaning <- replace_number(files$VERBATIM)
file_cleaning <- replace_abbreviation(file_cleaning)
file_cleaning <- replace_contraction(file_cleaning)
file_cleaning <- tolower(file_cleaning)
file_cleaning <- removePunctuation(file_cleaning)
file_cleaning[467]
file_cleaned <- stripWhitespace(file_cleaning)
custom_stops <- c("Bank")
file_cleaning_stops <- c(custom_stops, stopwords("en"))
file_cleaned_stopped<- removeWords(file_cleaning,file_cleaning_stops)
file_cleaned_corups<- VCorpus(VectorSource(file_cleaned))
file_cleaned_tdm <-TermDocumentMatrix(file_cleaned_corups)
dim(file_cleaned_tdm) # Number of terms <number of documents
file_cleaned_mx <- as.matrix(file_cleaned_tdm)
file_cleaned_corups<- VCorpus(VectorSource(file_cleaned_stopped))
file_cleaned_tdm <-TermDocumentMatrix(file_cleaned_corups)
file_cleaned_mx <- as.matrix(file_cleaned_tdm)
dim(file_cleaned_mx)
file_cleaned_mx[220:225, 475:478]
coffee_m <- as.matrix(coffee_tdm)
term_frequency <- rowSums(file_cleaned_mx)
term_frequency <- sort(term_frequency, decreasing = TRUE)
term_frequency[1:10]
BigramTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 2, max = 2))
bigram_dtm <- TermDocumentMatrix(file_cleaned_corups, control = list(tokenize = BigramTokenizer))
dim(bigram_dtm)
bigram_bi_mx <- as.matrix(bigram_dtm)
term_frequency <- rowSums(bigram_bi_mx)
term_frequency <- sort(term_frequency, decreasing = TRUE)
term_frequency[1:15]
freq_bigrams <- findFreqTerms(bigram_dtm, 25)
freq_bigrams}
数据集样本:
> dput(droplevels(head(files,4)))
structure(list(Score = c(10L, 10L, 10L, 7L), Comments = structure(c(4L,
3L, 1L, 2L), .Label = c("They are nice an quick. 3 years with them, and no issue.",
"Staff not very friendly.",
"I have to called them 3 times. They are very slow.",
"Quick and easy. High value."
), class = "factor")), row.names = c(NA, 4L), class = "data.frame")