Paul Martinez
2023-11-29
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 507340 27.1 1119345 59.8 660394 35.3
## Vcells 918893 7.1 8388608 64.0 1770800 13.6
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.3.2
## Loading required package: tm
## Warning: package 'tm' was built under R version 4.3.2
## Loading required package: NLP
## Warning: package 'NLP' was built under R version 4.3.1
##
## Attaching package: 'NLP'
## The following object is masked from 'package:ggplot2':
##
## annotate
## Loading required package: stringi
## Warning: package 'stringi' was built under R version 4.3.2
## Loading required package: wordcloud
## Warning: package 'wordcloud' was built under R version 4.3.2
## Loading required package: RColorBrewer
if (!require("RColorBrewer")) { install.packages("RColorBrewer") }
if (!require("dplyr")) { install.packages("dplyr") }## Loading required package: dplyr
## Warning: package 'dplyr' was built under R version 4.3.2
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
## Loading required package: slam
## Warning: package 'slam' was built under R version 4.3.1
## Loading required package: data.table
##
## Attaching package: 'data.table'
## The following object is masked from 'package:slam':
##
## rollup
## The following objects are masked from 'package:dplyr':
##
## between, first, last
# download file, if not present already
if( ! file.exists("Coursera-SwiftKey.zip") ){
src_zip_file <- "https://d396qusza40orc.cloudfront.net/dsscapstone/dataset/Coursera-SwiftKey.zip"
download.file(src_zip_file, destfile = "Coursera-SwiftKey.zip")
unzip("Coursera-SwiftKey.zip")
}
# look at the source files
zip_files <- unzip("Coursera-SwiftKey.zip", list = T)
zip_files$Date <- NULL
zip_files$Language <- substr(zip_files$Name, 7, 8)
zip_files$Length_in_Mb <- zip_files$Length/(1024^2)
zip_files <- zip_files[zip_files$Length>0,]
ggplot(zip_files, aes(x = Name, y = Length_in_Mb, fill = Language)) +
geom_bar(stat="identity") +
coord_flip() +
theme_light() +
xlab("") + ylab("File size in Mb")# only load twitter
zip_files <- zip_files[ grep("en_US", zip_files$Name), ]
for (file in zip_files$Name) {
con <- file(file, "r")
file_content <- readLines(con, encoding = "UTF-8")
print( paste("File:", file, "has in-memory size of:") )
print(object.size(file_content), units="Mb")
close(con)
# dynamically create variable names
assign(basename(file), file_content)
file_content <- NULL
}## Warning in readLines(con, encoding = "UTF-8"): line 167155 appears to contain
## an embedded nul
## Warning in readLines(con, encoding = "UTF-8"): line 268547 appears to contain
## an embedded nul
## Warning in readLines(con, encoding = "UTF-8"): line 1274086 appears to contain
## an embedded nul
## Warning in readLines(con, encoding = "UTF-8"): line 1759032 appears to contain
## an embedded nul
## [1] "File: final/en_US/en_US.twitter.txt has in-memory size of:"
## 319 Mb
## Warning in readLines(con, encoding = "UTF-8"): incomplete final line found on
## 'final/en_US/en_US.news.txt'
## [1] "File: final/en_US/en_US.news.txt has in-memory size of:"
## 19.8 Mb
## [1] "File: final/en_US/en_US.blogs.txt has in-memory size of:"
## 255.4 Mb
## [1] 179857
## [1] 472029
## [1] 15451
hist( stri_count_words(ds.blogs), breaks=30, col=rainbow(50), main = paste("Number of words distribution for", prettyNum(length(ds.blogs), scientific=FALSE, big.mark=","), "documents" ))hist( stri_count_words(ds.tweets), breaks=30, col=rainbow(50), main = paste("Number of words distribution for", prettyNum(length(ds.tweets), scientific=FALSE, big.mark=","), "documents" ))hist( stri_count_words(ds.news), breaks=30, col=rainbow(50), main = paste("Number of words distribution for", prettyNum(length(ds.news), scientific=FALSE, big.mark=","), "documents" ))## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 9.00 28.00 41.74 60.00 2294.00
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 7.00 12.00 12.77 18.00 42.00
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.00 19.00 32.00 34.65 46.00 532.00
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1.0 47.0 156.0 229.9 329.0 10785.0
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.00 37.00 64.00 68.76 100.00 140.00
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3.0 112.0 186.0 202.8 269.0 2900.0
-In this presentation I covered how to upload the data set
-I also provided histograms for each data set
-Overall this milestone allowed for exploratory analysis
-I plan to create a predictive algorithm