predict.constant: Classify Multivariate Observations Based on the Constant...

Description Usage Arguments Details Value See Also Examples

View source: R/constant.R

Description

Classify multivariate observations in conjunction with constant.

Usage

1
2
  ## S3 method for class 'constant'
 predict(object, newdata, ...)

Arguments

object

Object of class "constant".

newdata

A data.frame of cases to be classified or, if object has a formula, a data.frame with columns of the same names as the variables used. A vector will be interpreted as a row vector. If newdata is missing, an attempt will be made to retrieve the data used to fit the constant object.

...

Further arguments.

Details

This function is a method for the generic function predict() for class "constant". It can be invoked by calling predict(x) for an object x of the appropriate class, or directly by calling predict.constant(x) regardless of the class of the object.

Value

A list with components:

class

The predicted class labels (a factor).

posterior

Matrix of class posterior probabilities.

See Also

constant.

Examples

 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 <- constant(diabetes ~ ., data = PimaIndiansDiabetes, weights = ws,
    subset = train)
pred <- predict(fit, newdata = PimaIndiansDiabetes[-train,])
mean(pred$class != PimaIndiansDiabetes$diabetes[-train])

locClass documentation built on May 2, 2019, 5:21 p.m.