Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to train data in Neural Network

Asked by Turki on 13 Nov 2013
Latest activity Commented on by Greg Heath on 12 Feb 2014

Hi all,

I am working on neural network to study cancer data, which has 680 record and labels. I just want to study the data and classify them to e classes. I've tried to write a code on matlab and I got result. But I don't know if it's correct or not.

So could you help me?

Thanks in advance.

close all, clear all, format compact 
[num]= xlsread('Cdata2.xlsx');
[r,c] = size(num);          
x = num(: ,1:c-1);
t = num(:,c);
inputs = x';
targets = t';
% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
% Set up Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,inputs,targets);
% Test the Network
outputs = net(inputs);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs);
perf = mse(net,targets,outputs);
% View the Network
view(net)
figure, plotregression(targets,outputs)
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
figure, plotconfusion(targets,outputs)
%figure, ploterrhist(errors)

0 Comments

Turki

Products

No products are associated with this question.

1 Answer

Answer by Greg Heath on 14 Nov 2013
Accepted answer

You need to

 1. Initialize the RNG before train so that you can duplicate your results
 2. Convert your output to percent error rates or correct classification rates for 
    the train/val/test subsets of each class.
 3. Search using
    greg patternnet
 for some examples.

Hope this helps.

Thank you for formally accepting my answer

Greg

P.S. If you try your code on one of the MATLAB classification examples, we can compare results

help nndatasets

3 Comments

Turki on 14 Nov 2013

About the first point: what is the benefit of using random number generation?

I didn't understand enough the second point. How can I classify the three sets correctly?!

Thank you

Turki on 14 Nov 2013

Hi Greg,

Can you help me please? I am new in this field and I'm really lost here.

Thanks

Greg Heath on 12 Feb 2014

Sorry I missed you in Nov. I usually search on the word "neural".

Any more questions?

Greg Heath

Contact us