楼主: 拯救Dingo
6391 1

[程序分享] 神经网络ANN模型的预测值置信区间 nnetpredint R 包支持 nnet, neuralnet, RSNNS [推广有奖]

  • 0关注
  • 0粉丝

初中生

38%

还不是VIP/贵宾

-

威望
0
论坛币
139 个
通用积分
0.0452
学术水平
7 点
热心指数
7 点
信用等级
7 点
经验
195 点
帖子
10
精华
0
在线时间
7 小时
注册时间
2012-3-29
最后登录
2024-1-17

楼主
拯救Dingo 发表于 2015-12-29 08:02:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
R中对机器学习支持的比较流行的包有nnet, neuralnet 和RSNNS等。目前nnet只支持单一隐含层hidden layer的网络训练,而neuralnet 包则支持multi-layer neuralnet works 模型的训练。如果把神经网络当做一个regression拟合问题看,需要构建一个如95%的CI置信区间,考虑到训练集的训练误差(model error) 和 随机噪音 noise。根据一些如下文献中的方法实现了简单R包 nnetpredint,目前支持nnet, neuralnet 和 RSNNS 训练的模型object。这种估计方法的核心思想是根据训练集trainning datasets 获得 Jacobian Matrix (gradient function)。详细Math可以参考以下几篇文献 Neural Networks Prediction Intervals:

http://wenku.baidu.com/view/a505b8a0011ca300a7c39005.html

http://mirror.bjtu.edu.cn/cran/web/packages/nnetpredint/nnetpredint.pdf


  1. # neuralnet 训练神经网络模型,结构为 c(13,5,3,1)
  2. library(MASS)
  3. data <- Boston
  4. maxs <- apply(data, 2, max)
  5. mins <- apply(data, 2, min)
  6. scaled <- as.data.frame(scale(data, center = mins, scale = maxs - mins)) # normalization
  7. index <- sample(1:nrow(data),round(0.75*nrow(data)))
  8. train_ <- scaled[index,]
  9. test_ <- scaled[-index,]
  10. library(neuralnet) # Training
  11. n <- names(train_)
  12. f <- as.formula(paste("medv ~", paste(n[!n %in% "medv"], collapse = " + ")))
  13. nn <- neuralnet(f,data = train_,hidden = c(5,3),linear.output = FALSE)
  14. plot(nn)
  15. library(nnetpredint) # Getting prediction confidence interval
  16. x <- train_[,-14]
  17. y <- train_[,14]
  18. newData <- test_[,-14]
  19. # S3 generic method: Object of nn
  20. yPredInt <- nnetPredInt(nn, x, y, newData)
  21. print(yPredInt[1:20,])
复制代码






二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Neural 置信区间 神经网络 Pred NET 置信区间 神经网络 ANN

已有 1 人评分学术水平 热心指数 信用等级 收起 理由
雪凤夏洛 + 1 + 1 + 1 精彩帖子

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

沙发
拯救Dingo 发表于 2015-12-30 00:11:37
# RSNNS 包的例子
http://wenku.baidu.com/view/a505b8a0011ca300a7c39005.html
  1. # Example 3: Using the rsnns object trained by RSNNS package
  2. library(RSNNS)
  3. data(iris)
  4. #shuffle the vector
  5. iris <- iris[sample(1:nrow(iris),length(1:nrow(iris))),1:ncol(iris)]
  6. irisValues <- iris[,1:4]
  7. irisTargets <- decodeClassLabels(iris[,5])[,'setosa']
  8. iris <- splitForTrainingAndTest(irisValues, irisTargets, ratio=0.15)
  9. iris <- normTrainingAndTestSet(iris)
  10. model <- mlp(iris$inputsTrain, iris$targetsTrain, size=5, learnFuncParams=c(0.1),
  11. maxit=50, inputsTest=iris$inputsTest, targetsTest=iris$targetsTest)
  12. predictions <- predict(model,iris$inputsTest)
  13. # Generating prediction intervals
  14. library(nnetpredint)
  15. # S3 Method for rsnns class prediction intervals
  16. xTrain <- iris$inputsTrain
  17. yTrain <- iris$targetsTrain
  18. newData <- iris$inputsTest
  19. yPredInt <- nnetPredInt(model, xTrain, yTrain, newData)
  20. print(yPredInt[1:20,])
复制代码

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-26 00:17