gpt4 book ai didi

r - R 中的神经网络 - 为所有输入值获取相同的输出

转载 作者:行者123 更新时间:2023-12-02 13:43:33 25 4
gpt4 key购买 nike

我正在尝试准备一个神经网络,根据“否”和“年龄”两个参数来预测产品的 claim 数量。 以下数据集是神经网络的输入。

structure(list(no = c(25305.4104099149, 49282.7650363303, 71596.161588407, 
93100.2399492689, 120575.89348652, 138907.168168798, 152853.150129645,
164658.048266216, 203323.951054253, 217964.514231364, 232098.010631853,
245528.300551639, 257729.677107825, 273017.858354583, 289943.942081732,
307253.529762711, 322779.210756104, 338484.424561413, 354509.62945598,
376508.167449508, 392559.686167136, 406403.704572922, 418237.95321136,
428306.956736623, 443032.309329306, 462815.029777392, 483057.035564531,
501119.337852308, 516468.28989971, 529231.965438745, 546230.529378035),
age = c(63.5793740593707, 102.316649334314, 139.062062015527,
159.908188195329, 221.139098010716, 243.371632144127, 255.656705912817,
321.979062244126, 302.183543005839, 354.719062375634, 369.989444935937,
415.562730056562, 445.18103403067, 487.443822982359, 522.664771025013,
531.055799381952, 588.227179384567, 627.155320232965, 631.325866647729,
656.228738193787, 674.252217317525, 717.171080443709, 741.672049752712,
788.251261134812, 798.113504685438, 831.731613476353, 834.814816968948,
868.754851062387, 891.362029551517, 902.022293484355, 940.795814337874),
claims = c(430.964844652385, 732.996578820216, 1702.3121722574,
2251.25233558302, 2197.47809502525, 2567.04757960458, 3031.86042202782,
3156.90611199034, 3863.87816105778, 4111.89975688297, 3775.93067659216,
4012.49766196774, 4312.44312947351, 4180.22855748422, 5089.44484309535,
4257.88997259059, 4880.90586497903, 4463.20376379347, 4240.41527392955,
4784.76670484109, 5402.00394657619, 4599.18095060565, 4003.91468429224,
4029.72081951048, 3774.73142127963, 3920.30299815048, 5640.00980484863,
5609.58082520698, 4689.03553448074, 5021.68591677232, 6583.74468086371),
expense = c(152020.866139235, 435514.001634924, 752077.230564814,
1206688.79158373, 1291739.60434588, 1421308.36224772, 2050740.38970347,
1975198.4497045, 2274222.98020964, 2579595.43870509, 2129258.22735162,
2135819.30924201, 2670328.44657756, 2908678.20678848, 2647633.44523976,
2416617.98013342, 2312104.28655066, 2603487.56885879, 2598480.12097434,
2747610.29007465, 2856983.01477582, 2453661.76656217, 2557917.28443019,
2952529.81656875, 2177766.2760928, 2077444.9802322, 3542576.76934085,
4050503.17869956, 3737028.1474149, 3497074.2505681, 3541174.73116362)),
.Names = c("no", "age", "claims", "expense"), row.names = c(NA, -31L),
class = "data.frame")

我正在尝试的神经网络是

claimnet = neuralnet(claims~no+age,data=claimdata,hidden=10,threshold=0.01,err.fct='sse')

我从 claimnet$net.result 获得的所有 31 条记录的输出/拟合结果为 3913.491497。当我尝试使用这个神经网络进行计算时,结果也是如此。我认为必须传递一些参数才能获得正确的输出。

请让我知道我哪里出错了。

最佳答案

我可能是错的,但我很确定您需要在训练人工神经网络之前对数据进行标准化。您可以使用标准评分方法将数据从 -1 标准化为 1。另外,请确保您的数据呈正态分布。但是,我不确定神经网络是否强制这样做。

使用您的数据,这就是我所做的。

plot(density(claimdata$no));shapiro.test(claimdata$no)
plot(density(claimdata$age));shapiro.test(claimdata$age)
plot(density((claimdata$claims)^2));shapiro.test(claimdata$claims^2)
claimdata$claimsSQ<- claimdata$claims^2

fml<- as.formula("claimsSQ ~ no + age");
data_Train<- claimdata[complete.cases(claimdata),];
scMeans<- apply(data_Train,2,mean);
scSTDEV<- apply(data_Train,2,sd);
sc_Train<- scale(data_Train);

#Select training samples
inTrain <- sample(1:nrow(sc_Train), floor(.9*nrow(sc_Train)));
# Get the predictor data
trainingPredictors <- sc_Train[inTrain, ];
# Get Data not used in Training set
testPredictors <- sc_Train[-inTrain,];

train.nnet<- nnet(fml,data=trainingPredictors,linout=T,
size = 2, rang = 0.1,decay = 5e-4, maxit = 200);

res.nnet<- predict(train.nnet,testPredictors);

results<- cbind(claimdata$claims[-inTrain],
sqrt(res.nnet*scSTDEV[5]+scMeans[5]));results;

另外,请看一下,“第 3 章 - 神经网络数据中的数据准备人工神经网络外汇汇率预测分析国际运筹学与管理科学丛书,第 107 卷,2007 年,第 39-62 页。

希望这有帮助,

干杯。

关于r - R 中的神经网络 - 为所有输入值获取相同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19946220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com