This function builds a random ferns model on the given training data.
rFerns(x, ...)# S3 method for formula
rFerns(formula, data = .GlobalEnv, ...)
# S3 method for matrix
rFerns(x, y, ...)
# S3 method for default
rFerns(
x,
y,
depth = 5,
ferns = 1000,
importance = "none",
saveForest = TRUE,
consistentSeed = NULL,
threads = 0,
...
)
Data frame containing attributes; must have unique names and contain only numeric, integer or (ordered) factor columns.
Factors must have less than 31 levels. No NA
values are permitted.
For formula and matrix methods, a place to state parameters to be passed to default method.
For the print method, arguments to be passed to print
.
alternatively, formula describing model to be analysed.
in which to interpret formula.
A decision vector. Must a factor of the same length as nrow(X)
for ordinary many-label classification, or a logical matrix with each column corresponding to a class for multi-label classification.
The depth of the ferns; must be in 1--16 range. Note that time and memory requirements scale with 2^depth
.
Number of ferns to be build.
Set to calculate attribute importance measure (VIM);
"simple"
will calculate the default mean decrease of true class score (MDTS, something similar to Random Forest's MDA/MeanDecreaseAccuracy),
"shadow"
will calculate MDTS and additionally MDTS of this attribute shadow, an implicit feature build by shuffling values within it, thus stripping it from information (which is slightly slower).
Shadow importance is useful as a reference to judge significance of a regular importance.
"none"
turns importance calculation off, for a slightly faster execution.
For compatibility with pre-1.2 rFerns, TRUE
will resolve to "simple"
and FALSE
to "none"
.
Abbreviation can be used instead of a full value.
Should the model be saved? It must be TRUE
if you want to use the model for prediction; however, if you are interested in importance or OOB error only, setting it to FALSE
significantly improves memory requirements, especially for large depth
and ferns
.
PRNG seed used for shadow importance only.
Must be either a 2-element integer vector or NULL
, which corresponds to seeding from the default PRNG.
Number or OpenMP threads to use. The default value of 0
means all available to OpenMP.
It should be set to the same value in two merged models to make shadow importance meaningful.
An object of class rFerns
, which is a list with the following components:
The built model; NULL
if saveForest
was FALSE
.
OOB approximation of accuracy. Ignores never-OOB-tested objects (see oobScores element).
The importance scores or NULL
if importance
was set to "none"
.
In a first case it is a data.frame
with two or three columns:
MeanScoreLoss
which is a mean decrease of a score of a correct class when a certain attribute is permuted,
Tries
which is number of ferns which utilised certain attribute, and, only when importance
was set to "shadow"
,
Shadow
, which is a mean decrease of accuracy for the correct class for a permuted copy of an attribute (useful as a baseline for normal importance).
The rownames
are set and equal to the names(x)
.
A matrix of OOB scores of each class for each object in training set.
Rows correspond to classes in the same order as in levels(Y)
.
If the ferns
is too small, some columns may contain NA
s, what means that certain objects were never in test set.
A vector of OOB predictions of class for each object in training set. Never-OOB-tested objects (see above) have predictions equal to NA
.
Confusion matrix build from oobPreds
and y
.
Time used to train the model (smaller than wall time because data preparation and model final touches are excluded; however it includes the time needed to compute importance, if it applies).
An object of difftime
class.
Numerical vector of three elements: classes
, depth
and ferns
, containing respectively the number of classes in decision and copies of depth
and ferns
parameters.
Copy of levels(Y)
after purging unused levels.
Consistent seed used; only present for importance="shadow"
.
Can be used to seed a new model via consistentSeed
argument.
Copy of the train set structure, required internally by predict method.
Ozuysal M, Calonder M, Lepetit V & Fua P. (2009). Fast Keypoint Recognition using Random Ferns, IEEE Transactions on Pattern Analysis and Machine Intelligence, 32(3), 448-461.
Kursa MB (2014). rFerns: An Implementation of the Random Ferns Method for General-Purpose Machine Learning, Journal of Statistical Software, 61(10), 1-13.
# NOT RUN {
set.seed(77)
#Fetch Iris data
data(iris)
#Build model
rFerns(Species~.,data=iris)
##Importance
rFerns(Species~.,data=iris,importance="shadow")->model
print(model$imp)
# }
Run the code above in your browser using DataLab