RRF | R Documentation |
RRF
implements the regularized random forest algorithm. It is based on
the randomForest R package by Andy Liaw, Matthew Wiener, Leo Breiman and Adele Cutler.
## S3 method for class 'formula' RRF(formula, data=NULL, ..., subset, na.action=na.fail) ## Default S3 method: RRF(x, y=NULL, xtest=NULL, ytest=NULL, ntree=500, mtry=if (!is.null(y) && !is.factor(y)) max(floor(ncol(x)/3), 1) else floor(sqrt(ncol(x))), replace=TRUE, classwt=NULL, cutoff, strata, sampsize = if (replace) nrow(x) else ceiling(.632*nrow(x)), nodesize = if (!is.null(y) && !is.factor(y)) 5 else 1, maxnodes = NULL, importance=FALSE, localImp=FALSE, nPerm=1, proximity, oob.prox=proximity, norm.votes=TRUE, do.trace=FALSE, keep.forest=!is.null(y) && is.null(xtest), corr.bias=FALSE, keep.inbag=FALSE, coefReg=NULL, flagReg=1, feaIni=NULL,...) ## S3 method for class 'RRF' print(x, ...)
data |
an optional data frame containing the variables in the model.
By default the variables are taken from the environment which
|
subset |
an index vector indicating which rows should be used. (NOTE: If given, this argument must be named.) |
na.action |
A function to specify the action to be taken if NAs are found. (NOTE: If given, this argument must be named.) |
x, formula |
a data frame or a matrix of predictors, or a formula
describing the model to be fitted (for the
|
y |
A response vector. If a factor, classification is assumed,
otherwise regression is assumed. If omitted, |
xtest |
a data frame or matrix (like |
ytest |
response for the test set. |
ntree |
Number of trees to grow. This should not be set to too small a number, to ensure that every input row gets predicted at least a few times. |
mtry |
Number of variables randomly sampled as candidates at each
split. Note that the default values are different for
classification (sqrt(p) where p is number of variables in |
replace |
Should sampling of cases be done with or without replacement? |
classwt |
Priors of the classes. Need not add up to one. Ignored for regression. |
cutoff |
(Classification only) A vector of length equal to number of classes. The ‘winning’ class for an observation is the one with the maximum ratio of proportion of votes to cutoff. Default is 1/k where k is the number of classes (i.e., majority vote wins). |
strata |
A (factor) variable that is used for stratified sampling. |
sampsize |
Size(s) of sample to draw. For classification, if sampsize is a vector of the length the number of strata, then sampling is stratified by strata, and the elements of sampsize indicate the numbers to be drawn from the strata. |
nodesize |
Minimum size of terminal nodes. Setting this number larger causes smaller trees to be grown (and thus take less time). Note that the default values are different for classification (1) and regression (5). |
maxnodes |
Maximum number of terminal nodes trees in the forest
can have. If not given, trees are grown to the maximum possible
(subject to limits by |
importance |
Should importance of predictors be assessed? |
localImp |
Should casewise importance measure be computed?
(Setting this to |
nPerm |
Number of times the OOB data are permuted per tree for assessing variable importance. Number larger than 1 gives slightly more stable estimate, but not very effective. Currently only implemented for regression. |
proximity |
Should proximity measure among the rows be calculated? |
oob.prox |
Should proximity be calculated only on “out-of-bag” data? |
norm.votes |
If |
do.trace |
If set to |
keep.forest |
If set to |
corr.bias |
perform bias correction for regression? Note: Experimental. Use at your own risk. |
keep.inbag |
Should an |
coefReg |
the coefficient(s) of regularization. A smaller coefficient may lead to a smaller feature subset, i.e. there are fewer variables with non-zero importance scores. coefReg must be either a single value (all variables have the same coefficient) or a numeric vector of length equal to the number of predictor variables. default: 0.8 |
flagReg |
1: with regularization; 0: without regularization. default: 1 |
feaIni |
initial feature subset, useful only when flagReg = 1 |
... |
optional parameters to be passed to the low level function
|
An object of class RRF
, which is a list with the
following components:
call |
the original call to |
type |
one of |
predicted |
the predicted values of the input data based on out-of-bag samples. |
importance |
a matrix with |
importanceSD |
The “standard errors” of the permutation-based
importance measure. For classification, a |
localImp |
a p by n matrix containing the casewise importance
measures, the [i,j] element of which is the importance of i-th
variable on the j-th case. |
ntree |
number of trees grown. |
mtry |
number of predictors sampled for spliting at each node. |
forest |
(a list that contains the entire forest; |
err.rate |
(classification only) vector error rates of the prediction on the input data, the i-th element being the (OOB) error rate for all trees up to the i-th. |
confusion |
(classification only) the confusion matrix of the prediction (based on OOB data). |
votes |
(classification only) a matrix with one row for each input data point and one column for each class, giving the fraction or number of (OOB) ‘votes’ from the random forest. |
oob.times |
number of times cases are ‘out-of-bag’ (and thus used in computing OOB error estimate) |
proximity |
if |
feaSet |
features selected |
mse |
(regression only) vector of mean square errors: sum of squared
residuals divided by |
rsq |
(regression only) “pseudo R-squared”: 1 - |
test |
if test set is given (through the |
For large data sets, especially those with large number of variables, calling RRF via the formula interface is not advised: There may be too much overhead in handling the formula.
Houtao Deng softwaredeng@gmail.com, based on the randomForest R package by Andy Liaw, Matthew Wiener, Leo Breiman and Adele Cutler.
Houtao Deng and George C. Runger (2013), Gene Selection with Guided Regularized Random Forest, Pattern Recognition 46(12): 3483-3489.
Houtao Deng and George C. Runger (2012), Feature Selection via Regularized Trees, the 2012 International Joint Conference on Neural Networks (IJCNN).
Houtao Deng (2013), Guided Random Forest in the RRF Package, arXiv:1306.0237.
#-----Example 1 ----- library(RRF);set.seed(1) #only the first feature and last feature are truly useful X <- matrix(runif(50*50), ncol=50) class <- (X[,1])^2 + (X[,50])^2 class[class>median(class)] <- 1; class[class<=median(class)] <- 0 #ordinary random forest. rf <- RRF(X,as.factor(class), flagReg = 0) impRF <- rf$importance impRF <- impRF[,"MeanDecreaseGini"] rf$feaSet #regularized random forest rrf <- RRF(X,as.factor(class), flagReg = 1) rrf$feaSet #guided regularized random forest imp <- impRF/(max(impRF))#normalize the importance score gamma <- 0.5 coefReg <- (1-gamma)+gamma*imp #weighted average grrf <- RRF(X,as.factor(class),coefReg=coefReg, flagReg=1) grrf$feaSet #guided random forest gamma <- 1 coefReg <- (1-gamma)+gamma*imp grf <- RRF(X,as.factor(class),coefReg=coefReg, flagReg=0) grf$feaSet #-----Example 2 XOR learning----- #only the first 3 features are needed #and each individual feature is not useful #bSample <- sample(0:1,20000,replace=TRUE) #X <- matrix(bSample,ncol=40) #class <- xor(xor(X[,1],X[,2]),X[,3])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.