K-fold neural network returns only training data

Hello,
I'm working on a task to practice my capabilities of working with neural networks. However, I came across a very strange problem, one that I wasn't able to work out on my own. I asked my teacher for help, but we weren't able to find the cause, either. That's why I'm reaching out here - I hope that maybe some of you came across a similar situation and know how to solve it.
I'm making a k-fold validated neural network that classifies genes by their expression values. To help me with that, I used the cvpartition function.
First, I load and format my data for further processing. Then, I use cvpartition to define the indexes for every iteration and create a cell that contains those values. I also create an empty vector to hold the results from each iteration for comparison and quality assessment. After that, I start iterating. For each iteration, I take out information from my data vectors that corresponds to the indices returned by cvpartition. I then make a trainMatrix and validMatrix cell that contains first the data, then the classification result (-1 or 1) and use them to train and simulate the network.
load Data_PTC_vs_FTC.mat
genedata = Data.X;
geneclass = Data.D';
gene(1,:) = Data.X(1,:);
gene(2,:) = Data.X(50,:);
gene=gene';
k = 10;
cv = cvpartition(length(gene),'kfold',k);
trainIndices=cell(1,10);
testIndices=cell(1,10);
class_result_total=[];
for i=1:k
trainIndices{i} = find(training(cv,i));
testIndices{i} = find(test(cv,i));
trainMatrix{i} = [gene(trainIndices{i}) geneclass(trainIndices{i})];
validMatrix{i} = [gene(testIndices{i}) geneclass(testIndices{i})];
net = newp(gene(trainIndices{i}),geneclass(trainIndices{i}),'hardlims','learnpn');
net.trainParam.epochs=200;
net = train(net,trainMatrix{i}(:,1),trainMatrix{i}(:,2));
class_result = sim(net, validMatrix{i}(:,1));
class_result_total=[class_result_total class_result];
end
It seems fine, but... instead of classifying the 9 values I give to my network, the network gives out a vector of the ~77 class values I gave it for training. I have tested all the references to the cells and they are correct, as well as assigned them to new variables. This didn't help.
I'm not sure what to do anymore - the code seems correct. I could try to rewrite the whole thing without using cvpartition, but I feel like there's not much of a point when the error lies somewhere during training. I really hope that maybe someone here will be able to help me.

Answers (0)

Products

Asked:

sal
on 12 May 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!