当我在nnet()中使用权重时,我有一条错误消息,即使包文档说权重。但是,如果我使用wts它是有效的。如果我没有输入任何值,我认为重量默认为1.
无论我输入的wts值是什么,nnet()总是返回权重= 83,如何分配83个权重?请看下面的输出:
我想我真的不明白如何分配这些权重
任何帮助表示赞赏。谢谢。
attach(iris)
library(caret)
set.seed(3456)
trainIndex <- createDataPartition(iris$Species, p = .8,
list = F,
times = 1)
irisTrain <- iris[ trainIndex,]
irisTest <- iris[-trainIndex,]
irispred <- nnet(Species ~ ., data=irisTrain ,weights = 1, size=10)
predicted <- predict(irispred,irisTest,type="class")
使用权重时出错(包文档说明使用权重)
irispred <- nnet(Species ~ ., data=irisTrain ,weights = 1, size=10)
Error in model.frame.default(formula = Species ~ ., data = irisTrain, :
variable lengths differ (found for '(weights)')
如果我使用wts没有错误:
irispred <- nnet(Species ~ ., data=irisTrain ,wts = 1, size=10)
# weights: 83
initial value 148.744330
iter 10 value 20.508558
iter 20 value 7.683385
iter 30 value 5.719438
iter 40 value 3.831845
iter 50 value 3.524789
iter 60 value 3.461561
iter 70 value 3.352866
iter 80 value 3.061214
iter 90 value 3.049519
iter 100 value 3.001406
final value 3.001406
stopped after 100 iterations
irispred$wts
[1] 0.46982680904 -1.08944343286 -0.85761073123 -2.05356837297 -1.56599897345
[6] 291.18284632141 31.85356741288 27.37999662827 -97.45738049129 -55.50299935575
[11] -1.36175718738 .......Up to 83.
> irispred <- nnet(Species ~ ., data=irisTrain ,wts = 28, size=10)
# weights: 83
initial value 143.546315
iter 10 value 55.502915
iter 20 value 40.514073
iter 30 value 6.610363
iter 40 value 6.111119
iter 50 value 6.019070
iter 60 value 5.963004
iter 70 value 5.956329
iter 80 value 5.945786
iter 90 value 5.942088
iter 100 value 5.939509
final value 5.939509
stopped after 100 iterations
> irispred$wts
[1] 1.07816704818 1.89161925466 1.36901821472 -0.39336454435 -0.23879356006
[6] -0.63780061885 -2.62845406757 ... up to 83