Skip to content

Commit

Permalink
Revised style and fixed filenames for Chapter 6 code.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmyleswhite committed Feb 17, 2012
1 parent dea04fb commit 99c346c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions 06-Regularization/chapter06.R
Original file line number Diff line number Diff line change
Expand Up @@ -343,15 +343,24 @@ for (lambda in lambdas)
{
performance <- rbind(performance,
data.frame(Lambda = lambda,
RMSE = rmse(test.y, with(test.df, predict(glmnet.fit, poly(X,
degree = 10), s = lambda)))))
RMSE = rmse(test.y,
with(test.df,
predict(glmnet.fit,
poly(X, degree = 10),
s = lambda)))))
}

# Twenty-third code snippet
ggplot(performance, aes(x = Lambda, y = RMSE)) +
geom_point() +
geom_line()

# Alternative plot not shown in the book.
ggplot(performance, aes(x = Lambda, y = RMSE)) +
geom_point() +
geom_line() +
scale_x_log10()

# Twenty-fourth code snippet
best.lambda <- with(performance, Lambda[which(RMSE == min(RMSE))])

Expand All @@ -375,7 +384,8 @@ coef(glmnet.fit, s = best.lambda)
#10 0.0000000

# Twenty-sixth code snippet
ranks <- read.csv('data/oreilly.csv', stringsAsFactors = FALSE)
ranks <- read.csv(file.path('data', 'oreilly.csv'),
stringsAsFactors = FALSE)

library('tm')

Expand Down

0 comments on commit 99c346c

Please sign in to comment.