当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


R predict.nnet 通过训练有素的神经网络预测新示例


R语言 predict.nnet 位于 nnet 包(package)。

说明

通过训练有素的神经网络预测新的例子。

用法

## S3 method for class 'nnet'
predict(object, newdata, type = c("raw","class"), ...)

参数

object

nnet 返回的类 nnet 的对象。

newdata

测试示例的矩阵或 DataFrame 。向量被认为是包含单个情况的行向量。

type

输出类型

...

传递给其他方法或从其他方法传递的参数。

细节

此函数是类 "nnet" 的通用函数 predict() 的方法。可以通过为适当类的对象 x 调用 predict(x) 来调用它,也可以直接通过调用 predict.nnet(x) 来调用它,而不管对象的类如何。

如果是 type = "raw" ,则为经过训练的网络返回的值矩阵;如果 type = "class" ,则对应的类(可能仅在网络由 nnet.formula 生成时才有用)。

例子

# 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"))

参考

Ripley, B. D. (1996) Pattern Recognition and Neural Networks. Cambridge.

Venables, W. N. and Ripley, B. D. (2002) Modern Applied Statistics with S. Fourth edition. Springer.

也可以看看

nnet , which.is.max

相关用法


注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Predict New Examples by a Trained Neural Net。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。