The goal of this project is just to display that you’ve gotten used to working with the data and that you are on track to create your prediction algorithm. Please submit a report on R Pubs that explains your exploratory analysis and your goals for the eventual app and algorithm. This document should be concise and explain only the major features of the data you have identified and briefly summarize your plans for creating the prediction algorithm and Shiny app in a way that would be understandable to a non-data scientist manager. You should make use of tables and plots to illustrate important summaries of the data set. The motivation for this project is to:
Demonstrate that you’ve downloaded the data and have successfully loaded it in.
Create a basic report of summary statistics about the data sets.
Report any interesting findings that you amassed so far.
Get feedback on your plans for creating a prediction algorithm and Shiny app.
Review criteria:
Does the link lead to an HTML page describing the exploratory analysis of the training data set?
Has the data scientist done basic summaries of the three files? Word counts, line counts and basic data tables?
Has the data scientist made basic plots, such as histograms to illustrate features of the data?
Was the report written in a brief, concise style, in a way that a non-data scientist manager could appreciate?
options(timeout = 500)
link <- "https://d396qusza40orc.cloudfront.net/dsscapstone/dataset/Coursera-SwiftKey.zip"
download.file(link, destfile = "Coursera-SwiftKey.zip", mode = "wb")
unzip("Coursera-SwiftKey.zip")
blogs <- "./final/en_US/en_US.blogs.txt"
news <- "./final/en_US/en_US.news.txt"
twitter <- "./final/en_US/en_US.twitter.txt"
blogs_size <- file.size(blogs)/(2^20)
news_size <- file.size(news)/(2^20)
twitter_size <- file.size(twitter)/(2^20)
blogs_lines <- (readLines(blogs, skipNul = TRUE))
news_lines <- (readLines(news, skipNul = TRUE))
## Warning in readLines(news, skipNul = TRUE): incomplete final line found on
## './final/en_US/en_US.news.txt'
twitter_lines <- (readLines(twitter, skipNul = TRUE))
blogs_total_lines <- length(blogs_lines)
news_total_lines <- length(news_lines)
twitter_total_lines <- length(twitter_lines)
blogs_chars_line <- nchar(blogs_lines)
news_chars_line <- nchar(news_lines)
twitter_chars_line <- nchar(twitter_lines)
blogs_total_chars <- sum(blogs_chars_line)
news_total_chars <- sum(news_chars_line)
twitter_total_chars <- sum(twitter_chars_line)
library(stringi)
blogs_words_line <- stri_count_words(blogs_lines)
news_words_line <- stri_count_words(news_lines)
twitter_words_line <- stri_count_words(twitter_lines)
blogs_total_words <- sum(blogs_words_line)
news_total_words <- sum(news_words_line)
twitter_total_words <- sum(twitter_words_line)
final_values <- data.frame(Files = c("blogs file", "news file", "twitter file"),
Size = c(blogs_size, news_size, twitter_size),
Lines = c(blogs_total_lines, news_total_lines, twitter_total_lines),
Chars = c(blogs_total_chars, news_total_chars, twitter_total_chars),
Words = c(blogs_total_words, news_total_words, twitter_total_words))
library(knitr)
kable(final_values)
| Files | Size | Lines | Chars | Words |
|---|---|---|---|---|
| blogs file | 200.4242 | 899288 | 206824509 | 37546806 |
| news file | 196.2775 | 77259 | 15639408 | 2674561 |
| twitter file | 159.3641 | 2360148 | 162122861 | 30096690 |
set.seed(12345)
blogs_words_line_sample <- sample(blogs_words_line, length(blogs_words_line) * 0.01)
news_words_line_sample <- sample(news_words_line, length(news_words_line) * 0.01)
twitter_words_line_sample <- sample(twitter_words_line, length(twitter_words_line) * 0.01)
rm(blogs_words_line, news_words_line, twitter_words_line)
hist(blogs_words_line_sample,
main="Words per Line in Blogs",
xlab="Words per Line",
col="green")
hist(news_words_line_sample,
main="Words per Line in News",
xlab="Words per Line",
col="red")
hist(twitter_words_line_sample,
main="Words per Line in Twitter",
xlab="Words per Line",
col="lightblue")
In the final plot, the impact of Twitter’s word limit is evident. However, across all three files, the word count per line is relatively low, indicating that the messages are concise. This brevity will be a significant factor to consider during the implementation of the prediction algorithm.