Skip to content

Readability and other minor edits #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.DS_Store
.dropbox
*.Rhistory
code_check*
nohup.out
+*.pdf
*.pdf
*.csv
slides/01-Slides/cache
slides/01-Slides/data
slides/05-Slides/cache


2 changes: 1 addition & 1 deletion 03-Classification/email_classify.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ ggsave(plot = ex1,
# words as features
get.msg <- function(path)
{
con <- file(path, open = "rt", encoding = "latin1")
con <- file(path, open = "rb", encoding = "latin1")
text <- readLines(con)
# The message always begins after the first full line break
msg <- text[seq(which(text == "")[1] + 1, length(text), 1)]
Expand Down
3 changes: 2 additions & 1 deletion 04-Ranking/priority_inbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pattern1 <- "%a, %d %b %Y %H:%M:%S"
pattern2 <- "%d %b %Y %H:%M:%S"

allparse.df$Date <- date.converter(allparse.df$Date, pattern1, pattern2)
allparse.df$Date <- as.POSIXct(allparse.df$Date)

# Convert emails and subjects to lower-case
allparse.df$Subject <- tolower(allparse.df$Subject)
Expand All @@ -142,7 +143,7 @@ priority.df <- allparse.df[with(allparse.df, order(Date)), ]
priority.train <- priority.df[1:(round(nrow(priority.df) / 2)), ]

# The first step is to create rank weightings for all of the features.
# We begin with the simpliest: who the email is from.
# We begin with the simplest: who the email is from.

# Calculate the frequency of correspondence with all emailers in the training set
from.weight <- ddply(priority.train, .(From.EMail),
Expand Down
1 change: 1 addition & 0 deletions 05-Regression/chapter05.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Otherwise you will see errors when loading data or saving figures!

library('ggplot2')
dir.create("images")

# First snippet
ages <- read.csv(file.path('data', 'longevity.csv'))
Expand Down
1 change: 1 addition & 0 deletions 06-Regularization/chapter06.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# Otherwise you will see errors when loading data or saving figures!

library('ggplot2')
library('Hmisc')

# First snippet
set.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion 07-Optimization/chapter07.R
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ propose.modified.cipher <- function(cipher)
# Seventeenth code snippet
load(file.path('data', 'lexical_database.Rdata'))

# Eighteength code snippet
# Eighteenth code snippet
lexical.database[['a']]
lexical.database[['the']]
lexical.database[['he']]
Expand Down
2 changes: 1 addition & 1 deletion 10-Recommendations/chapter10.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ row.names(user.package.matrix) <- user.package.matrix[, 1]
user.package.matrix <- user.package.matrix[, -1]

# Tenth code snippet
similarities <- cor(user.package.matrix)
suppressWarnings(similarities <- cor(user.package.matrix))

nrow(similarities)
#[1] 2487
Expand Down
4 changes: 2 additions & 2 deletions 11-SNA/02_twitter_net.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ user.net <- set.vertex.attribute(user.net, "Label", value = get.vertex.attribut

# Next, extract the 2-core, and remove pendants generated as a result
user.cores <- graph.coreness(user.net, mode = "in")
user.clean <- subgraph(user.net, which(user.cores > 1) - 1)
user.clean <- induced.subgraph(user.net, which(user.cores > 1) - 1)

# Finally, extract ego.net
user.ego <- subgraph(user.net, c(0, neighbors(user.net, user, mode = "out")))
user.ego <- induced.subgraph(user.net, c(0, neighbors(user.net, user, mode = "out")))

# Add hierarchical clustering data to network
user.sp <- shortest.paths(user.ego)
Expand Down
4 changes: 3 additions & 1 deletion fast_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ source('chapter10.R')
setwd('..')

#setwd('11-SNA')
#source('chapter09.R')
#source('01_google_sg.R')
#source('02_twitter_net.R')
#source('03_twitter_rec.R')
#setwd('..')

setwd('12-Model_Comparison')
Expand Down
2 changes: 1 addition & 1 deletion package_installer.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cran.packages <- c("e1071",
"tm",
"XML")

cat("This script will now attempt to install all of the R packages used in 'Machine Learning for Hackers'")
cat("This script will now attempt to install all of the R packages used in 'Machine Learning for Hackers'\n")

for(p in cran.packages) {
if(!suppressWarnings(require(p, character.only = TRUE, quietly = TRUE))) {
Expand Down