【发布时间】:2020-05-11 15:45:31
【问题描述】:
过去,我在为我的一个文档构建 tf-idf 方面得到了帮助,并得到了我想要的输出(请参见下文)。
TagSet <- data.frame(emoticon = c("????","????","????","????","????"),
stringsAsFactors = FALSE)
TextSet <- data.frame(tweet = c("????Sharp, adversarial⚔️~pro choice????~ban Pit Bulls☠️~BSL????️~aberant psychology????~common sense????~the Piper will lead us to reason????~sealskin woman????",
"Blocked by Owen, Adonis. Abbott & many #FBPE???? Love seaside, historic houses & gardens, family & pets. RTs & likes/ Follows may=interest not agreement ????????",
"???????????????????????????????? #healthy #vegetarian #beatchronicillness fix infrastructure",
"LIBERTY-IDENTITARIAN. My bio, photo at Site Info. And kindly add my site to your Daily Favorites bar. Thank you, Eric",
"????????I #BackTheBlue for my son!???????? Facts Over Feelings. Border Security saves lives! #ThankYouICE",
"???????????????????? I play Pedal Steel @CooderGraw & #CharlieShafter???????????????? #GoStars #LiberalismIsAMentalDisorder",
"#Englishman #Londoner @Chelseafc ????️♂️ ???????? ???? ????????????????????????????????????????????",
"F*** the Anti-White Agenda #Christian #Traditional #TradThot #TradGirl #European #MAGA #AltRight #Folk #Family #WhitePride",
"????????❄️Do not dwell in tbaconhe past, do not dream of the future, concentrate the mind on the present moment.????????️❄️",
"Ordinary girl in a messed up World | Christian | Anti-War | Anti-Zionist | Pro-Life | Pro ???????? | ????????Hello intro on the Minds Link |"),
stringsAsFactors = FALSE)
library(dplyr)
library(quanteda)
tweets_dfm <- dfm(TextSet$tweet) # convert to document-feature matrix
tweets_dfm %>%
dfm_select(TagSet$emoticon) %>% # only leave emoticons in the dfm
dfm_tfidf() %>% # weight with tfidf
convert("data.frame") # turn into data.frame to display more easily
# document ???? ???? ???? ???? ????
# 1 text1 1.39794 1 0 0 0
# 2 text2 0.00000 0 1 0 0
# 3 text3 0.00000 0 0 0 0
# 4 text4 0.00000 0 0 0 0
# 5 text5 0.00000 0 0 0 0
# 6 text6 0.69897 0 0 0 0
# 7 text7 0.00000 0 0 1 1
# 8 text8 0.00000 0 0 0 0
# 9 text9 0.00000 0 0 0 0
# 10 text10 0.00000 0 0 0 0
但我需要一些帮助来计算每个奇异项的 tf-idf。意思是,如何准确地从矩阵中获取每个术语的 tf-idf 值?
# terms tfidf
# ???? #its tfidf the correct way
# ???? #its tfidf the correct way
# ???? #its tfidf the correct way
# ???? #its tfidf the correct way
# ???? #its tfidf the correct way
我敢肯定,这不像从它的矩阵列中为一个术语添加所有 tf-idf 并除以它出现的文档。这就是该术语的价值。
我查看了一些来源,例如这里,https://stats.stackexchange.com/questions/422750/how-to-calculate-tf-idf-for-a-single-term,但作者提出的问题完全来自我阅读的内容。
我目前在文本挖掘/分析术语方面很薄弱。
【问题讨论】: