R語言
predict.nnet
位於 nnet
包(package)。 說明
通過訓練有素的神經網絡預測新的例子。
用法
## S3 method for class 'nnet'
predict(object, newdata, type = c("raw","class"), ...)
參數
object |
|
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.
也可以看看
相關用法
- R nnet 擬合神經網絡
- R which.is.max 求向量中的最大位置
- R class.ind 從因子生成類別指標矩陣
- R nnetHess 評估神經網絡的 Hessian 矩陣
- R multinom 擬合多項對數線性模型
- R Pixel X 射線像素強度隨時間的變化
- R corARMA ARMA(p,q) 相關結構
- R getGroupsFormula 提取分組公式
- R corRatio 有理二次相關結構
- R logLik.glsStruct glsStruct 對象的對數似然
- R intervals.lmList lmList 係數的置信區間
- R corLin 線性相關結構
- R plot.augPred 繪製 augPred 對象
- R print.varFunc 打印 varFunc 對象
- R recalc 重新計算壓縮線性模型對象
- R Variogram.corSpher 計算 corSpher 對象的半變異函數
- R getGroups.lme 提取 lme 對象組
- R nlmeStruct 非線性混合效應結構
- R predict.nlme 來自 nlme 對象的預測
- R corSymm 一般相關結構
- R qqnorm.gls gls 對象殘差的正態圖
- R pdCompSymm 具有複合對稱結構的正定矩陣
- R [.pdMat 下標 pdMat 對象
- R pdConstruct.pdBlocked 構造 pdBlocked 對象
- R gapply 按組應用函數
注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Predict New Examples by a Trained Neural Net。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。