subset.wsrf | R Documentation |
Obtain a subset of a forest.
## S3 method for class 'wsrf' subset(x, trees, ...)
x |
an object of class |
trees |
which trees should be included in the sub-forest. An integer vector, which indicates the index of the trees. |
... |
not used. |
An object of class wsrf
.
combine
library("wsrf") # Prepare parameters. ds <- iris target <- "Species" vars <- names(ds) if (sum(is.na(ds[vars]))) ds[vars] <- randomForest::na.roughfix(ds[vars]) ds[target] <- as.factor(ds[[target]]) form <- as.formula(paste(target, "~ .")) set.seed(42) train <- sample(nrow(ds), 0.7*nrow(ds)) test <- setdiff(seq_len(nrow(ds)), train) # Build model. We disable parallelism here, since CRAN Repository # Policy (https://cran.r-project.org/web/packages/policies.html) # limits the usage of multiple cores to save the limited resource of # the check farm. model.wsrf <- wsrf(form, data=ds[train, vars], parallel=FALSE) print(model.wsrf) # Subset. submodel.wsrf <- subset.wsrf(model.wsrf, 1:200) print(submodel.wsrf) cl <- predict(submodel.wsrf, newdata=ds[test, vars], type="response")$response actual <- ds[test, target] (accuracy.wsrf <- mean(cl==actual))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.