-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpos_tfidf.R
60 lines (46 loc) · 1.41 KB
/
pos_tfidf.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
if(FALSE){
# -*- coding: utf-8 -*-
"
Created on Tue Nov 26 21:27:12 2019
@author: chenxinye
"
}
library(pacman)
p_load(jiebaR,wordcloud2,tidyverse,tidytext,data.table,rio)
setwd('I:/E-commerce information mining/history')
df_ps <- read.csv("pos_all.csv", header=T)
df_ps %>% bind_tf_idf(
term = word,
document = id,
n = frequency
) -> df_ps
df_ps %>% unnest() %>% count(id,word) -> f_table
filter_word <- c('米粉',
'我家',
'爱',
'第二次',
'未填写',
'做个',
'总体',
'方法'
)
tf_idf <- f_table %>% bind_tf_idf(
term = word,
document = id,
n = n
)
for (i in filter_word){
tf_idf <- tf_idf[which(tf_idf$word != i),]
}
top10 <- tf_idf %>% group_by(id) %>% top_n(10,tf_idf)
top10 <- top10 %>% ungroup()
worditem <- data.frame(top10$word,top10$tf_idf)
worditem <- worditem[order(worditem$top10.tf_idf, decreasing = T),]
worditem <- worditem[!duplicated(worditem$top10.word),]
worditem_get <- head(worditem,100)
worditem_get %>% wordcloud2(color = "random-dark",
size = 0.6,
minSize = 0.2,
shape = "alias of square",
rotateRatio=0.2)
write.csv(worditem, "pos_worditem.csv", row.names = FALSE)