Learn R Programming

validann (version 1.2.1)

predict.ann: Predict new examples using a trained neural network.

Description

Predict new examples using a trained neural network.

Usage

# S3 method for ann
predict(object, newdata = NULL, derivs = FALSE, ...)

Arguments

object
an object of class `ann' as returned by function ann.
newdata
matrix, data frame or vector of input data. A vector is considered to comprise examples of a single input or predictor variable. If x is NULL, fitted outputs derived from object will be returned.
derivs
logical; should derivatives of hidden and output nodes be returned? Default is FALSE.
additional arguments affecting the predictions produced (not currently used).

Value

if derivs = FALSE, a vector of predictions is returned. Otherwise, a list with the following components is returned:
values
matrix of values returned by the trained ANN.
derivs
matrix of derivatives of hidden (columns 1:object$size) and output (final column) nodes.

Details

This function is a method for the generic function predict() for class `ann'. It can be invoked by calling predict(x) for an object x of class `ann'. predict.ann produces predicted values, obtained by evaluating the `ann' model given newdata, which contains the inputs to be used for prediction. If newdata is omitted, the predictions are based on the data used for the fit. Derivatives may be returned for sensitivity analyses, for example.

See Also

ann

Examples

Run this code
## fit 1-hidden node `ann' model to ar9 data
data("ar9")
samp <- sample(1:1000, 200)
y <- ar9[samp, ncol(ar9)]
x <- ar9[samp, -ncol(ar9)]
x <- x[, c(1,4,9)]

fit <- ann(x, y, size = 1, act_hid = "tanh", act_out = "linear", rang = 0.1)

## get model predictions based on a new sample of ar9 data.
samp <- sample(1:1000, 200)
y <- ar9[samp, ncol(ar9)]
x <- ar9[samp, -ncol(ar9)]
x <- x[, c(1,4,9)]

sim <- predict(fit, newdata = x)

## if derivatives are required...
tmp <- predict(fit, newdata = x, derivs = TRUE)
sim <- tmp$values
derivs <- tmp$derivs

Run the code above in your browser using DataLab