如何测试神经网络训练的模型?

76次观看(过去30天)
琼娜
琼娜 2020年3月7日
评论道: 琼娜2020年3月13日
我使用神经网络进行分类,我知道如何为一个主题做到这一点,通过训练:测试:验证集。但我想用一个主体的全部数据训练我的网络,然后用另一个主体的数据测试它。
我不知道该怎么做。如何将标签和测试输入传递给模型。
我已经搜索并学会了保存网络,然后加载它并以新的测试集作为输入运行。我明白了,但是标签呢,我该如何传递测试集的新标签呢?
请帮助!
下面是代码:
清除所有
trainFcn = 'trainscg';%缩放共轭梯度反向传播。
hiddenLayerSize = [10 10 10];
net = patternnet(hiddenLayerSize, trainFcn);
选择输入和输出前/后处理功能。
对于所有处理函数的列表,输入help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
设置培训、验证、测试数据部门
对于所有数据除法函数的列表,键入:help nndivision
网divideFcn = ' diverand ';随机划分数据
网divideMode = 'sample';把每个样本分开
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 10/100;
net.divideParam.testRatio = 20/100;
%%选择性能功能
对于所有性能函数的列表,输入help nnperformance
网performFcn = 'crossentropy';%叉
net.trainParam。Max_fail = 300;
net.trainParam。Min_grad = 0.00000001;
%选择绘图功能
对于所有plot函数的列表,键入:help nnplot
网plotFcns = {'plotperform','plottrainstate',' plotterrorist ',…
“plotconfusion”、“plotroc '};
训练网络
[net,tr] = train(net,Input_Signals,Labels);
测试网络
y = net(Input_Signals);
e = gsubtract(标签,y);
performance = perform(net,Labels,y)
tind = vec2ind(标签);
Yind = vec2ind(y);
percentterrors = sum(tind ~= yind)/numel(tind);
重新计算培训、验证和测试表现
trainTargets =标签。* tr.trainMask{1};
valTargets =标签。* tr.valMask{1};
testTargets =标签。* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance =执行(net,valTargets,y)
testPerformance =执行(net,testTargets,y)
%%查看网络
视图(净)

答案(1)

Srivardhan Gadila
Srivardhan Gadila 2020年3月11日
在“Test the Network section”中替换你上面的代码 Input_Signals 与新的测试集和 标签 带有新测试集的标签。
1评论
琼娜
琼娜 2020年3月13日
我这么做了,但它把所有东西都归为一类,结果是50%的准确率。尽管我在训练和测试每个类的样本数量相同的模型。
你知道是什么问题吗?
我也实施了LDA,在一个集合上进行训练,在另一个集合上进行测试,但结果是相同的50-53%。我不知道为什么。

登录评论。

社区寻宝

在MATLAB Central中找到宝藏,并发现社区如何帮助您!

开始狩猎!