Predictive models in R: a new book in Polish

December 14, 2012

(This article was first published on R snippets, and kindly contributed to R-bloggers)

Together with Mateusz Zawisza I have just published a new book in Polish on building predictive models in GNU R. It can be bought at Oficyna Wydawnicza SGH. The book presents complete examples of basic data mining processes.
Although the book is in Polish, sources of all procedures used in it, which are available on my website, can be used without the book. Here is a simplified code from exercise 4.5 presenting neural network bagging:

X <- seq(-2, 2, length.out = SAMPLE_SIZE)
TRUE_Y <- X ^ 2 / 2 + sin(4 * X)
y <- TRUE_Y + 2 * rnorm(SAMPLE_SIZE)
GetBootstrapPrediction <- function() {
  bootstrap.indices <- sample(SAMPLE_SIZE, replace = T)
  bootstrap.sample.y <- y[bootstrap.indices]
  bootstrap.sample.x <- X[bootstrap.indices]
  bootstrap.model <- nnet(bootstrap.sample.y ~bootstrap.sample.x,
    lin = T, size = 4, trace = FALSE, maxit = 10 ^ 6)
  return(predict(bootstrap.model, data.frame(bootstrap.sample.x = X)))
} <- winProgressBar(“Progress in %”, “0% done”, 0, 1, 0)
bootstrap.predictions <- rep(0, SAMPLE_SIZE)
  bootstrap.predictions <-bootstrap.predictions +
  percentage <- i / BOOTSTRAP_REPLICATIONS
  setWinProgressBar(, percentage, “Progress in %”,
    sprintf(“%d%% done”, round(100 * percentage)))
plot(X, y,xlim = c(-2, 2), ylim = c(-5, 6))
lines(X, TRUE_Y, lwd = 4)    

lines(X, bootstrap.predictions /BOOTSTRAP_REPLICATIONS,
  lwd = 3, col = 3)

It produces the following graph. Circles represent training data, black line is true relationship and green line is prediction from bagging procedure:

To leave a comment for the author, please follow the link and comment on their blog: R snippets. offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)