-
Notifications
You must be signed in to change notification settings - Fork 0
/
imdb text mining.R
52 lines (34 loc) · 1.21 KB
/
imdb text mining.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
# Load imdb database
imdb <- read.csv("IMDB Top 50.csv")
# Convert to characters
imdb$Description <- as.character(imdb$Description)
# Load text mining package
library(tm)
# Load SnowballC package
library(SnowballC)
# Load RColorBrewer package
library(RColorBrewer)
#summary
summary(imdb)
# Convert description into a corpus
Corpus <- Corpus(VectorSource(imdb$Description))
# Convert terms to lower case
Corpus <- tm_map(Corpus, content_transformer(tolower))
# Remove punctuation
Corpus <- tm_map(Corpus, removePunctuation)
# Remove stop words from corpus
Corpus <- tm_map(Corpus, removeWords, stopwords("English"))
# Reduce terms to stems in corpus
Corpus <- tm_map(Corpus, stemDocument, "english")
# Strip whitespace from corpus
Corpus <- tm_map(Corpus, stripWhitespace)
# Convert corpus to text document
Corpus <- tm_map(Corpus, PlainTextDocument)
# Inspect first entry in the corpus
Corpus[[1]]$content
# Recrearting corpus as vector due to occurring error
Corpus <- Corpus(VectorSource(Corpus))
# Load the wordcloud package
library(wordcloud)
# Create a frequency word cloud
wordcloud( words = Corpus, max.words = 100, scale = c(2,0.2), colors=brewer.pal(8,"Dark2"))