Description Usage Arguments Details Value See Also Examples
A classifier that always predicts the class with the highest weighted prior probability.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | majority(x, ...)
## S3 method for class 'formula'
majority(formula, data, weights = rep(1, nrow(data)), ...,
subset, na.action)
## S3 method for class 'data.frame'
majority(x, ...)
## S3 method for class 'matrix'
majority(x, grouping, weights = rep(1, nrow(x)), ..., subset,
na.action = na.fail)
## Default S3 method:
majority(x, grouping, weights = rep(1, nrow(x)), ...)
|
x |
(Required if no |
formula |
A |
data |
A |
weights |
Observation weights to be used in the fitting process, must be non-negative. |
subset |
An index vector specifying the cases to be used in the training sample. (NOTE: If given, this argument must be named.) |
na.action |
A function to specify the action to be taken if |
grouping |
(Required if no |
... |
Further arguments. |
The majority classifier usually serves to determine a baseline for more sophisticated classification methods. This function is also a helper function needed to combine mixture models and recursive partitioning with a majority classifier. The weighted prior probabilities are calculated as
p_g = ∑_{n:y_n=g} w_n/(∑_n w_n)
An object of class "majority"
, a list
containing the following components:
prior |
Weighted class prior probabilities. |
counts |
The number of observations per class. |
lev |
The class labels (levels of |
N |
The number of observations. |
weights |
The observation weights used in the fitting process. |
predictors |
The names of the predictor variables. |
call |
The (matched) function call. |
Other majority: majorityGenerative
,
predict.majorityGenerative
,
predict.majority
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | library(mlbench)
data(PimaIndiansDiabetes)
train <- sample(nrow(PimaIndiansDiabetes), 500)
# weighting observations from classes pos and neg according to their
# frequency in the data set:
ws <- as.numeric(1/table(PimaIndiansDiabetes$diabetes)
[PimaIndiansDiabetes$diabetes])
fit <- majority(diabetes ~ ., data = PimaIndiansDiabetes, weights = ws,
subset = train)
pred <- predict(fit, newdata = PimaIndiansDiabetes[-train,])
mean(pred$class != PimaIndiansDiabetes$diabetes[-train])
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.