【发布时间】:2016-04-15 22:26:09
【问题描述】:
我正在寻找在神经网络中应用 10 倍交叉验证的示例。我需要这个问题的链接答案:Example of 10-fold SVM classification in MATLAB
我想对所有 3 个类进行分类,而在示例中只考虑了两个类。
编辑:这是我为 iris 示例编写的代码
load fisheriris %# load iris dataset
k=10;
cvFolds = crossvalind('Kfold', species, k); %# get indices of 10-fold CV
net = feedforwardnet(10);
for i = 1:k %# for each fold
testIdx = (cvFolds == i); %# get indices of test instances
trainIdx = ~testIdx; %# get indices training instances
%# train
net = train(net,meas(trainIdx,:)',species(trainIdx)');
%# test
outputs = net(meas(trainIdx,:)');
errors = gsubtract(species(trainIdx)',outputs);
performance = perform(net,species(trainIdx)',outputs)
figure, plotconfusion(species(trainIdx)',outputs)
end
matlab 给出的错误:
Error using nntraining.setup>setupPerWorker (line 62)
Targets T{1,1} is not numeric or logical.
Error in nntraining.setup (line 43)
[net,data,tr,err] = setupPerWorker(net,trainFcn,X,Xi,Ai,T,EW,enableConfigure);
Error in network/train (line 335)
[net,data,tr,err] = nntraining.setup(net,net.trainFcn,X,Xi,Ai,T,EW,enableConfigure,isComposite);
Error in Untitled (line 17)
net = train(net,meas(trainIdx,:)',species(trainIdx)');
【问题讨论】:
-
您需要先提供一些代码。至少展示你如何在没有交叉验证的情况下实现神经网络,以及你试图调整什么参数。也看看这个答案:stackoverflow.com/a/28168462/1011724,所有你需要改变的是
fun函数 -
我没有任何代码。任何像 Iris 这样的数据库都可以。基本上,您发送的答案和问题中的链接都适用于 SVM。但是我不知道如何在 Matlab 中训练和测试 NN 分类器。分类器的任何规范都没有任何重要性
-
堆栈溢出不是代码编写服务。当您遇到编码问题时,这是一个寻求帮助的论坛。您需要先自己尝试一下!您是否阅读过有关在 MATLAB 中训练神经网络的文档?
-
是的,当然我自己试过了,我收到了意外的错误答案或错误。
-
您的错误是因为如果您查看
species,您会看到它是一个分类变量(即不是数字或逻辑)。你需要把它分成3个binary dummy variables
标签: matlab machine-learning neural-network classification cross-validation