r - 如何防止神经网络/插入符号/R中的“算法不收敛”错误?
问题描述
我正在尝试使用train
函数训练神经网络并neuralnet
作为我的method
参数来预测时间表。
我也在扩展我的训练数据集。
即使我为 my 尝试了不同learningrate
的 s、stepmax
es 和threshold
s neuralnet
,但每次我尝试使用train
函数训练网络时,其中一个 k-folds 碰巧每次都失败了
1:算法在 stepmax 内的 1 次重复中没有收敛。2:Fold05.Rep1 的预测失败:layer1=8, layer2=0, layer3=0 cbind(1, pred) %*% weights[[num_hidden_layers + 1]] 中的错误:需要数字/复杂矩阵/向量参数
我猜这是因为权重是随机的,所以每次我碰巧得到一些不会收敛的权重。
有没有办法阻止这种情况?也许试图重新训练使用不同权重失败的特定折叠?
这是我的代码:
library(caret)
library(neuralnet)
# Create the dataset
tt = data.frame(multiplier = rep(1:10, times = 10), multiplicand = rep(1:10, each = 10))
tt = cbind(tt, data.frame(product = tt$multiplier * tt$multiplicand))
# Splitting
indexes = createDataPartition(tt$product,
times = 1,
p = 0.7,
list = FALSE)
tt.train = tt[indexes,]
tt.test = tt[-indexes,]
# Pre-process
preProc <- preProcess(tt, method = c('center', 'scale'))
tt.preProcessed <- predict(preProc, tt)
tt.preProcessed.train <- tt.preProcessed[indexes,]
tt.preProcessed.test <- tt.preProcessed[-indexes,]
# Train
train.control <- trainControl(method = "repeatedcv",
number = 10,
repeats = 3)
tune.grid <- expand.grid(layer1 = 8,
layer2 = 0,
layer3 = 0)
tt.cv <- train(product ~ .,
data = tt.preProcessed.train,
method = 'neuralnet',
tuneGrid = tune.grid,
trControl = train.control,
linear.output = TRUE,
algorithm = 'backprop',
learningrate = 0.01,
stepmax = 500000,
lifesign = 'minimal',
threshold = 0.01)
解决方案
推荐阅读
- javascript - javascript中的移动按钮
- php - readdir while循环未执行
- python - Pyspark - 调用空数据框时 withColumn 不起作用
- windows - 尽管密码更改,如何保持任务在任务计划程序中运行
- angular - IdentityServer 的基于 Angular 的登录页面
- swift - swift: 将 long/int64 转换为日期
- raspberry-pi - Raspberry Pi3、R307 指纹传感器、UART 连接不起作用。
- java - 已注册/登录程序,但无法保存一个以上的个人资料
- sql - INTO 关键字的错误信息
- javascript - 为什么我的价值观未定义?