-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextMiningQandA.R
More file actions
183 lines (138 loc) · 4.38 KB
/
Copy pathTextMiningQandA.R
File metadata and controls
183 lines (138 loc) · 4.38 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#set to the appropriate working directory
setwd('/Users/Kristie/Documents/R/careervillage')
#WordClouds
library(quanteda)
library(quanteda.textplots)
library(quanteda.textstats)
library(quanteda.textmodels)
library(stopwords)
#QUESTIONS TITLE
summary(questions)
sum(is.na(questions$questions_title))
myCorpus <- corpus(questions$questions_title)
summary(myCorpus)
myDfm <- dfm(tokens(myCorpus))
# Simple frequency analyses
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
# Remove stop words and perform stemming
myDfm <- dfm(tokens(myCorpus,
remove_punc = T) )
myDfm <- dfm_remove(myDfm, stopwords('english'))
myDfm <- dfm_wordstem(myDfm)
dim(myDfm)
topfeatures(myDfm,60)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
#QUESTIONS BODY
summary(questions)
sum(is.na(questions$questions_body))
myCorpus <- corpus(questions$questions_body)
summary(myCorpus)
myDfm <- dfm(tokens(myCorpus))
# Simple frequency analyses
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
# Remove stop words and perform stemming
myDfm <- dfm(tokens(myCorpus,
remove_punc = T) )
myDfm <- dfm_remove(myDfm, stopwords('english'))
myDfm <- dfm_wordstem(myDfm)
dim(myDfm)
topfeatures(myDfm,60)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
# Add more user-defined stop words
stopwords1 <-c('#colleg','go','get','can','also')
myDfm <- dfm_remove(myDfm, stopwords1)
dim(myDfm)
topfeatures(myDfm,30)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
#ANSWERS BODY
summary(answers)
sum(is.na(answers$answers_body))
myCorpus <- corpus(answers$answers_body)
summary(myCorpus)
myDfm <- dfm(tokens(myCorpus))
# Simple frequency analyses
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
# Remove stop words and perform stemming
myDfm <- dfm(tokens(myCorpus,
remove_punc = T) )
myDfm <- dfm_remove(myDfm, stopwords('english'))
myDfm <- dfm_wordstem(myDfm)
dim(myDfm)
topfeatures(myDfm,60)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
# Add more user-defined stop words
stopwords1 <-c('<','>','p','can','get','br','li')
myDfm <- dfm_remove(myDfm, stopwords1)
dim(myDfm)
topfeatures(myDfm,30)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
#JOIN questions and question scores
library(dplyr)
summary(questions)
summary(question_scores)
question_scores <- question_scores %>% rename(questions_id = id)
questions_full <- left_join(questions,question_scores)
summary(questions_full)
#range of score values
max(questions_full$score, na.rm=TRUE) - min(questions_full$score, na.rm=TRUE)
table(questions_full$score)
#WordCloud for question TITLE that get more likes
questions_liked <- questions_full %>% filter(score > 5)
myCorpus <- corpus(questions_liked$questions_title)
summary(myCorpus)
myDfm <- dfm(tokens(myCorpus))
# Simple frequency analyses
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
# Remove stop words and perform stemming
myDfm <- dfm(tokens(myCorpus,
remove_punc = T) )
myDfm <- dfm_remove(myDfm, stopwords('english'))
myDfm <- dfm_wordstem(myDfm)
dim(myDfm)
topfeatures(myDfm,60)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
#WordCloud for question BODY that get more likes
myCorpus <- corpus(questions_liked$questions_body)
summary(myCorpus)
myDfm <- dfm(tokens(myCorpus))
# Simple frequency analyses
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
# Remove stop words and perform stemming
myDfm <- dfm(tokens(myCorpus,
remove_punc = T) )
myDfm <- dfm_remove(myDfm, stopwords('english'))
myDfm <- dfm_wordstem(myDfm)
stopwords1 <-c('<','>','p','can','get','br','li')
myDfm <- dfm_remove(myDfm, stopwords1)
dim(myDfm)
topfeatures(myDfm,60)
tstat_freq <- textstat_frequency(myDfm)
head(tstat_freq, 20)
textplot_wordcloud(myDfm,max_words=200)
#most liked questions
questions_most_liked <- questions_full %>% filter(score > 27)
#JOIN answers and answer scores
summary(answers)
summary(answer_scores)
answer_scores <- answer_scores %>% rename(answers_id = id)
answers_full <- left_join(answers,answer_scores)
summary(answers_full)
#range of score values
table(answers_full$score)