请教大神我的这个关于BP神经网络的MATLAB代码究竟出了什么错

我的代码如下:clear;clc;shuru=[1305554.51662938.89877648.23955254.911182286.47605157.9976963... 我的代码如下:
clear;
clc;
shuru=[1305554.51 662938.89 877648.23 955254.91 1182286.47 605157.99 769639.28 1000855.67 1567936.19 712892.06 995621.47 1210817.23 1824825.89 805095.78 1357303.95 1913573.98 2221913.29 988940.37 1520540.25;
-535933.67 -265478.17 -358139.96 -390311.91 -484727.57 -240666.79 -312753.06 -408491.77 -644476.31 -284092.72 -405644.61 -495278.31 -750743.05 -320627.06 -555553.68 -786731.21 -914786.21 -395704.62 -622816.59;
190253.14 97770.16 127640.62 138952.91 172150.18 89252.23 111812.5 145619.16 228386.33 105038.33 144834.43 176107.03 265871.87 118663.71 197368.22 278538.97 323968.44 145708.66 220970.77 ]'; %/(')for zhuanzhi
shuchu=[7510 7907 7432 6989 6760 7124 7548 7422 8333 8333 9375 11011 12045 13207 13592 13530 13963 15819 16118];

net = newff(minmax(shuru),[19,1],{'purelin','purelin'},'trainscg');

net.trainParam.show=50;%
net.trainParam.lr=0.05;
net.trainParam.epochs=800;
net.trainParam.goal=0.00000001;
[net,tr]=train(net,shuru,shuchu);

net.iw{1,1};%隐层权值
net.b{1};%隐层阈值

net.lw{2,1};%输出层权值
net.b{2};%输出层阈值

sim(net,shuru)

结果运行的时候总是说出现以下问题:
Warning: NEWFF used in an obsolete way.
> In obs_use at 18
In newff>create_network at 127
In newff at 102
See help for NEWFF to update calls to the new argument list.

Error using trainscg (line 104)
Inputs and targets have different numbers of samples.

Error in network/train (line 106)
[net,tr] = feval(net.trainFcn,net,X,T,Xi,Ai,EW,net.trainParam);

可是我检查过N遍输入层和输出层各变量都是19个啊,为什么会这样呢?求救~谢谢
展开
yishu_fanhua
推荐于2017-12-15 · TA获得超过110个赞
知道答主
回答量:57
采纳率:0%
帮助的人:55.7万
展开全部
clear;
clc;
shuru=[1305554.51 662938.89 877648.23 955254.91 1182286.47 605157.99 769639.28 1000855.67 1567936.19 712892.06 995621.47 1210817.23 1824825.89 805095.78 1357303.95 1913573.98 2221913.29 988940.37 1520540.25;
-535933.67 -265478.17 -358139.96 -390311.91 -484727.57 -240666.79 -312753.06 -408491.77 -644476.31 -284092.72 -405644.61 -495278.31 -750743.05 -320627.06 -555553.68 -786731.21 -914786.21 -395704.62 -622816.59;
190253.14 97770.16 127640.62 138952.91 172150.18 89252.23 111812.5 145619.16 228386.33 105038.33 144834.43 176107.03 265871.87 118663.71 197368.22 278538.97 323968.44 145708.66 220970.77 ];%'; %/(')for zhuanzhi
% 此处不能转置,matlab神经网络工具箱默认是以列为一个样本,所以此处shuru矩阵应为19*3

shuchu=[7510 7907 7432 6989 6760 7124 7548 7422 8333 8333 9375 11011 12045 13207 13592 13530 13963 15819 16118];
% 相对应的是shuchu的列数也应等于19

% 额外提醒:鉴于你给的数据量纲之间差别太大,最好进行归一化处理

net = newff(shuru,shuchu,19,{'tansig'},'trainscg');% 注意这是R2012b版本的newff函数,与以前版本的应用格式有点不同,所以会出现:NEWFF used in an obsolete way.的错误
% 另外输入和输出的矩阵必须保证列相等,因为它是以一列作为一个样本,在这个程序中,是3个输入对应一个输出,所以19个样本输入对应19个样本输出

net.divideParam.trainRatio=1; % 训练集所占总样本的比重
net.divideParam.valRatio=0; % 验证集所占总样本的比重
net.divideParam.testRatio=0; % 测试集所占总样本的比重
net.trainParam.show=50;% 显示步长
net.trainParam.lr=0.0001; % 学习速率
net.trainParam.epochs=800; % 最大迭代次数
net.trainParam.goal=0.00000001; % 训练目标,一般是用均方差(mse)来作为训练目标
[net,tr]=train(net,shuru,shuchu);

net.iw{1,1};%隐层权值
net.b{1};%隐层阈值

net.lw{2,1};%输出层权值
net.b{2};%输出层阈值

Pre=sim(net,shuru);
rr=corrcoef(shuchu,Pre); %线性相关系数
figure
plot(shuchu,'g');
hold on
plot(Pre,'r');
figure
plot(shuchu,Pre,'*');
title(['线性相关系数r=',num2str(rr(1,2))]);
xlabel('shuchu');
ylabel('PredictData');
更多追问追答
追问
感谢大神!请问接下来如果我要给出一组新的自变量看计算机按之前训练情况预测的因变量值是多少应该怎么做?
追答
1、我上面的答案有点问题,就是19*3改成3*19,这样才是19列

2、对于新的输入如:newinput,你必须保证的你的newinput是一个3*n的数组
那么预测输出Predictoutput=sim(net,newinput),net是已经训练好的网络,Predictoutput将会是一个1*n的预测数组
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式