This document is constructed to show the mastery of various concepts in data management and analysis using tools of text manipulation. The project is based on a series of tasks using unformatted text data from a database of text messages, blog posts and news feeds.
The tasks include:
Data has been downloaded from the Coursera page.The process sets three files: blogs, news and twitter.
setwd("~/Documents/GitHub/Capstone Practice/final/en_US")
blogs <- file("en_US.blogs.txt", open="rb")
blogs <- readLines(blogs, encoding = "UTF-8", skipNul=TRUE)
news <- file("en_US.news.txt", open = "rb")
news <- readLines(news, encoding = "UTF-8", skipNul=TRUE)
twitter <- file("en_US.twitter.txt", open = "rb")
twitter <- readLines(twitter, encoding = "UTF-8", skipNul=TRUE)
The files vary in size from just over 150 Megabytes to over 200 Megabytes. Since “tweets” are limited to 140 characters in this dataset (must be old), it has more lines but a smaller size.The blog posts file has the most words hence size.
File.Name File.Size.MB. Num.of.rows Num.of.words Length.Longest.Line
1 blogs 200.4242 899288 37546239 40833
2 news 196.2775 1010242 34762395 11384
3 twitter 159.3641 2360148 30093413 140
The complete data file is too large for effective use in the exercise so the sample is 1% of each store of data. The three sample files are combined into a single file with far fewer rows.
The sample is now 42695 rows, 1% of the size of the combined total of the files.
Remove unnecassry elements from the sample file such as numbers, punctuation and stopwords.Doing this cleaning on the sample speeds the process.
Process the data for most common words then show the firt six rows of the frequencies for the most popular words.
word frequency
1 will 3142
2 just 3085
3 said 3085
4 one 2870
5 like 2773
6 can 2471
Process the data for most common two-word pairs then show the first six rows of the frequencies for the most popular pairs of words.
word frequency
1 right now 229
2 cant wait 211
3 new york 208
4 last year 161
5 high school 158
6 dont know 148
Process the data for the most common three-word patterns then show the first six rows of the frequencies for the most popular patterns.
word frequency
1 cant wait see 52
2 happy mothers day 39
3 new york city 26
4 let us know 22
5 cinco de mayo 19
6 happy new year 16
The frequencies of the N-grams decline as we add more words to the phrase. The process takes time and is computing intensive so there may be additional need for optimization of the code. However,it is very important to clean the data and eliminate the prepositions and other common words that fall into the category of “stopwords”. In this model the cleaning happened after the sampling which emphasizes the importance of efficient code to speed the process of cleaning if a larger data set is used for the final project.