Learn R Programming

partykit (version 1.0-0)

party-predict: Tree Predictions

Description

Compute predictions from party objects.

Usage

## S3 method for class 'party':
predict(object, newdata = NULL, \dots)
predict_party(party, id, newdata = NULL, ...)
## S3 method for class 'default':
predict_party(party, id, newdata = NULL, FUN = NULL, \dots) 
## S3 method for class 'constparty':
predict_party(party, id, newdata = NULL,
    type = c("response", "prob", "quantile", "density", "node"),
    at = if (type == "quantile") c(0.1, 0.5, 0.9),
    FUN = NULL, simplify = TRUE, ...)
## S3 method for class 'simpleparty':
predict_party(party, id, newdata = NULL,
    type = c("response", "prob", "node"), ...)

Arguments

object
objects of class party.
newdata
an optional data frame in which to look for variables with which to predict, if omitted, the fitted values are used.
party
objects of class party.
id
a vector of terminal node identifiers.
type
a character string denoting the type of predicted value returned, ignored when argument FUN is given. For "response", the mean of a numeric response, the predicted class for a categorical response o
FUN
a function to extract (default method) or compute (constparty method) summary statistics. For the default method, this is a function of a terminal node only, for the constparty
at
if the return value is a function (as the empirical cumulative distribution function or the empirical quantile function), this function is evaluated at values at and these numeric values are returned. If at
simplify
a logical indicating whether the resulting list of predictions should be converted to a suitable vector or matrix (if possible).
...
additional arguments.

Value

  • A list of predictions, possibly simplified to a numeric vector, numeric matrix or factor.

Details

The predict method for party objects computes the identifiers of the predicted terminal nodes, either for new data in newdata or for the learning samples (only possible for objects of class constparty). These identifiers are delegated to the corresponding predict_party method which computes (via FUN for class constparty) or extracts (class simpleparty) the actual predictions.

Examples

Run this code
## fit tree using rpart
  library("rpart")
  rp <- rpart(skips ~ Opening + Solder + Mask + PadType + Panel,
              data = solder, method = 'anova')

  ## coerce to `constparty'
  pr <- as.party(rp)

  ## mean predictions
  predict(pr, newdata = solder[c(3, 541, 640),])

  ## ecdf
  predict(pr, newdata = solder[c(3, 541, 640),], type = "prob")

  ## terminal node identifiers
  predict(pr, newdata = solder[c(3, 541, 640),], type = "node")

  ## median predictions
  predict(pr, newdata = solder[c(3, 541, 640),], 
          FUN = function(y, w = 1) median(y))

Run the code above in your browser using DataLab