res = xlsread('Copy_of_数据集.xlsx');input=res((1: 120), 2: 6)'; %载入输入数据 output=res((1: 120), 7 :9)'; %载入输出数据input_这段代码的预测结果为什么都是0train = input(1:80); outest_simu=mapminmax('reverse',an,outputps); tput_train =output(1:80); input_test = input(80:100); output_test =output(80:100); %节点个数 inputnum=3; % 输入层节点数量 hiddennum=10;% 隐含层节点数量 outputnum=2; % 输出层节点数量[inputn,inputps]=mapminmax(input_train,-1,1);%归一化到[-1,1]之间,inputps用来作下一次同样的归一化 [outputn,outputps]=mapminmax(output_train,-1,1);net=newff(inputn,outputn,hiddennum,{'tansig','purelin'},'trainlm');% 建立模型,传递函数使用purelin,采用梯度下降法训练 W1= net. iw{1, 1};%输入层到中间层的权值 B1 = net.b{1};%中间各层神经元阈值 W2 = net.lw{2,1};%中间层到输出层的权值 B2 = net. b{2};%输出层各神经元阈值net.trainParam.epochs=15000; net.trainParam.lr=0.01; net.trainParam.goal=0.0001; net=train(net,inputn,outputn);inputn_test=mapminmax('apply',input_test,inputps);an=sim(net,inputn_test);error=test_simu-output_test; figure('units','normalized','position',[0.119 0.2 0.38 0.5]) plot(output_test,'bo-') hold on plot(test_simu,'r*-') hold on.an = mapminmax('reverse', an, outputps); % 将预测结果反归一化 output_test = mapminmax('reverse', output_test, outputps); % 将真实结果反归一化 figure; plot(output_test(1,:), 'b-o'); hold on; plot(an(1,:), 'r-*'); legend('真实结果', '预测结果'); xlabel('样本编号'); ylabel('输出值'); title('预测结果和真实结果');
时间: 2024-03-02 07:53:10 浏览: 72
这段代码中没有进行预测操作,只是建立了一个神经网络模型并用已有数据进行了训练。因此,没有预测结果为0的问题。如果您有需要进行预测的数据,需要在模型训练完成后使用模型进行预测操作,具体方法如下:
1. 将需要预测的数据进行归一化处理,方法为使用之前训练数据的归一化参数进行归一化,如下:
```
input_test_normalized = mapminmax('apply', input_test, inputps);
```
2. 使用训练好的模型对归一化后的数据进行预测,如下:
```
predicted_output_normalized = sim(net, input_test_normalized);
```
3. 将预测结果反归一化,得到最终预测结果,如下:
```
predicted_output = mapminmax('reverse', predicted_output_normalized, outputps);
```
需要注意的是,在进行预测之前,需要先对输入数据进行归一化处理,然后再使用训练好的模型进行预测,最后将预测结果反归一化得到最终结果。
相关问题
代码解读,xlswrite('A_science_city_complexity.xlsx',city_complexity,'Sheet1','F2'); [num,txt,AAA]=xlsread('rca_2000.xlsx','Sheet1','A1:E306'); xlswrite('A_science_city_complexity.xlsx',AAA,'Sheet1','A1'); [num1,txt1]=xlsread('biaotou_city.xlsx','Sheet1','F1:T1'); xlswrite('A_science_city_complexity.xlsx',txt1,'Sheet1','F1');
这段代码是用 MATLAB 编写的,主要功能是将数据写入 Excel 文件中。具体来说,第一行代码将名为 city_complexity 的变量写入名为 A_science_city_complexity.xlsx 的 Excel 文件的 Sheet1 中的 F2 单元格中。第二行代码从名为 rca_2000.xlsx 的 Excel 文件的 Sheet1 中读取数据,并将其存储在 num、txt 和 AAA 三个变量中。第三行代码将 AAA 变量写入名为 A_science_city_complexity.xlsx 的 Excel 文件的 Sheet1 中的 A1 单元格中。第四行代码从名为 biaotou_city.xlsx 的 Excel 文件的 Sheet1 中读取数据,并将其存储在 txt1 变量中。最后一行代码将 txt1 变量写入名为 A_science_city_complexity.xlsx 的 Excel 文件的 Sheet1 中的 F1 单元格中。
D1 = xlsread('data.xlsx',1,'B2:Y25');
As an AI language model, I cannot access local files, but I can explain what this line of code does in MATLAB.
The function 'xlsread' in MATLAB is used to read numerical data from Excel spreadsheets.
The first argument 'data.xlsx' specifies the name of the Excel file that is being read.
The second argument '1' specifies the sheet number or name to read from. In this case, it is the first sheet.
The third argument 'B2:Y25' specifies the range of cells to read in the form of 'startcell:endcell'.
The output of this line of code is a matrix 'D1' that contains the numerical values from the specified range of cells in the Excel file.
阅读全文
相关推荐

















