最近被老板分配到文本挖掘的相关项目里面,感觉又有一种需要开辟全新道路的不祥的feel,之前对于文本挖掘相关工作不算十分了解,所以就前往data science的胜地kaggle那看了一下相关工作的流程,同时也找了一点数据练手。
项目介绍:
本次数据完全来自于kaggle中的Twitter数据,是关于世界杯的Tweets的消息,本次就根据这些短推特数据来进行文本挖掘和分析
数据介绍:
library(tidyverse)
library(tidytext)
library(visNetwork)
fifa<-read_csv(FIFA.csv)
glimpse(fifa)
————————————————————————————————————————————————
## Observations: 530,000
## Variables: 16
## $ ID <dbl> 1.013597e+18, 1.013597e+18, 1.013597e+18, 1.0...
## $ lang <chr> "en", "en", "en", "en", "en", "en", "en", "en...
## $ Date <dttm> 2018-07-02 01:35:45, 2018-07-02 01:35:44, 20...
## $ Source <chr> "Twitter for Android", "Twitter for Android",...
## $ len <int> 140, 139, 107, 142, 140, 140, 140, 138, 138, ...
## $ Orig_Tweet <chr> "RT @Squawka: Only two goalkeepers have saved...
## $ Tweet <chr> "Only two goalkeepers have saved three penalt...
## $ Likes <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
## $ RTs <int> 477, 1031, 488, 0, 477, 153, 4, 1, 2199, 5146...
## $ Hashtags <chr> "WorldCup,POR,ENG", "WorldCup", "worldcup", "...
## $ UserMentionNames <chr> "Squawka Football", "FC Barcelona,Ivan Rakiti...
## $ UserMentionID <chr> "Squawka", "FCBarcelona,ivanrakitic,HNS_CFF",...
## $ Name <chr> "Cayleb", "Febri Aditya", "??", "Frida Carril...
## $ Place <chr> "Accra", "Bogor", NA, "Zapopan, Jalisco", NA,...
## $ Followers <int> 861, 667, 65, 17, 137, 29, 208, 7, 1, 158, 34...
## $ Friends <int> 828, 686, 67, 89, 216, 283, 338, 9, 6, 245, 3...
数据表示的非常清晰,我们整个工作也用不到所有的数据列,所以我们选取了Source,Tweet,Hashtags,RTs,Name,Place。
EDA:
Tweet中出现的最多的单词是哪些:
fifa_tidy<-fifa %>% unnest_tokens(words,Tweet) %>% filter(!(words %in% stop_words$word)) %>% filter(str_detect(words,[a-z]))
fifa_tidy %>% count(words,sort = T) %>% top_n(20,wt=n) %>%
ggplot(aes(x=reorder(words,n),y=n))+geom_col(fill="#AAB7B8")+theme_bw()+
labs(y=,x=,title="Top words in tweets")+coord_flip()
看来所有的tweets里面,france,world,cup,final,congratulations都是出现最频繁的单词,和去年世界杯的现象还是很符合的。
fifa_tidy %>% filter(str_detect(Source,^Twitter for)) %>%
count(Source,words,sort = T) %>% group_by(Source) %>% top_n(10,wt=n) %>%
ggplot(aes(x=reorder(words,n),y=n,fill=Source))+geom_col()+
theme_bw()+facet_wrap(~Source,scales = "free",ncol = 2)+
labs(y=,x=,title="Top words of tweets in Each source")+coord_flip()+
theme(legend.position = "none")
这一块看的是从不同OS平台出现的单词频率有哪些,经过Twitter上网友的提醒,发现第一个『Tweet for iPhone』多了一个空格,也确实是自己一时的疏忽大意。