Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fit = function(x, y, wts, param, lev, last, classProbs, ...) {
- ## First fit the pls model, generate the training set scores,
- ## then attach what is needed to the random forest object to
- ## be used later
- ## plsr only has a formula interface so create one data frame
- dat <- x
- dat$y <- y
- pre <- plsr(y~ ., data = dat, ncomp = param$ncomp)
- scores <- predict(pre, x, type = "scores")
- colnames(scores) <- paste("score", 1:param$ncomp, sep = "")
- mod <- randomForest(scores, y, mtry = param$mtry, ...)
- mod$projection <- pre$projection
- mod
- }
- predict = function(modelFit, newdata, submodels = NULL) {
- ## Now apply the same scaling to the new samples
- scores <- as.matrix(newdata) %*% modelFit$projection
- colnames(scores) <- paste("score", 1:ncol(scores), sep = "")
- scores <- as.data.frame(scores)
- ## Predict the random forest model
- predict(modelFit, scores)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement