EVOLUTION-MANAGER
Edit File: predict.nnet.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Predict New Examples by a Trained Neural Net</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for predict.nnet {nnet}"><tr><td>predict.nnet {nnet}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2> Predict New Examples by a Trained Neural Net </h2> <h3>Description</h3> <p>Predict new examples by a trained neural net. </p> <h3>Usage</h3> <pre> ## S3 method for class 'nnet' predict(object, newdata, type = c("raw","class"), ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>object</code></td> <td> <p>an object of class <code>nnet</code> as returned by <code>nnet</code>. </p> </td></tr> <tr valign="top"><td><code>newdata</code></td> <td> <p>matrix or data frame of test examples. A vector is considered to be a row vector comprising a single case. </p> </td></tr> <tr valign="top"><td><code>type</code></td> <td> <p>Type of output </p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>arguments passed to or from other methods. </p> </td></tr></table> <h3>Details</h3> <p>This function is a method for the generic function <code>predict()</code> for class <code>"nnet"</code>. It can be invoked by calling <code>predict(x)</code> for an object <code>x</code> of the appropriate class, or directly by calling <code>predict.nnet(x)</code> regardless of the class of the object. </p> <h3>Value</h3> <p>If <code>type = "raw"</code>, the matrix of values returned by the trained network; if <code>type = "class"</code>, the corresponding class (which is probably only useful if the net was generated by <code>nnet.formula</code>). </p> <h3>References</h3> <p>Ripley, B. D. (1996) <em>Pattern Recognition and Neural Networks.</em> Cambridge. </p> <p>Venables, W. N. and Ripley, B. D. (2002) <em>Modern Applied Statistics with S.</em> Fourth edition. Springer. </p> <h3>See Also</h3> <p><code><a href="nnet.html">nnet</a></code>, <code><a href="which.is.max.html">which.is.max</a></code> </p> <h3>Examples</h3> <pre> # use half the iris data ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3]) targets <- class.ind( c(rep("s", 50), rep("c", 50), rep("v", 50)) ) samp <- c(sample(1:50,25), sample(51:100,25), sample(101:150,25)) ir1 <- nnet(ir[samp,], targets[samp,],size = 2, rang = 0.1, decay = 5e-4, maxit = 200) test.cl <- function(true, pred){ true <- max.col(true) cres <- max.col(pred) table(true, cres) } test.cl(targets[-samp,], predict(ir1, ir[-samp,])) # or ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]), species = factor(c(rep("s",50), rep("c", 50), rep("v", 50)))) ir.nn2 <- nnet(species ~ ., data = ird, subset = samp, size = 2, rang = 0.1, decay = 5e-4, maxit = 200) table(ird$species[-samp], predict(ir.nn2, ird[-samp,], type = "class")) </pre> <hr /><div style="text-align: center;">[Package <em>nnet</em> version 7.3-12 <a href="00Index.html">Index</a>]</div> </body></html>