How to load own data set into neural network?

10 views (last 30 days)
Hi,
I am fairly new to MATLAB and I would like help in understanding about datasets. For classification in neural network, the example for wine classification show:
[x,t] = wine_dataset;
size(x)
size(t)
net = patternnet(10);
view(net)
I have a dataset of input [8x4]matrix and target [4x4]matrix. How do I input this into neural network such that I can use the function patternnet?
Thanks in advance for your help.

Accepted Answer

Greg Heath
Greg Heath on 13 Jun 2013
Exactly as indicated in
help patternnet
and
doc patternnet
where
x = yourinput;
t = yourtarget; % target columns should be unit vectors with a single 1
DOCUMENTATION BUG: the default input is (10,'trainscg') NOT (20,'trainlm')!
close all, clear all, clc
[ x, t ] = iris_dataset;
[ I N ] = size(x) % [ 4 150 ]
[ O N ] = size(t) % [ 3 150 ]
trueclass = vec2ind(t);
MSE00 = mean(var(t',1)) % 0.222 biased MSE for naive constant output model
MSE00a = mean(var(t',0)) % 0.224 unbiased MSE for naive constant output model
Ntrn = N - 2*(0.15*N) % 105 default size of training set
Ntrneq = Ntrn*O % 315 Number of training equations
% Nw = (I+1)*H+(H+1)*O % No. of unknown weights for H hidden nodes
Hub = -1 + ceil( (Ntrneq-O)/(I+O+1))% 38 Upperbound for H if Ntrneq > Nw
H = floor(Hub/10)% 3 Desire Ntrneq >> Nw to mitigate noise and errors in data
Nw = (I+1)*H+(H+1)*O % 27 Number of unknown weights
Ndof = Ntrneq - Nw % 288 No. of estimation degrees of freedom
(See Wikipedia reference below)
MSEgoal = 0.01*Ndof*MSE00a/Ntrneq % 0.002 Desire adjusted R^2 >= 0.99
MinGrad = MSEgoal/10 % 2.05e-4
rng(0) % Initialize RNG
net = patternnet(H);
net.trainParam.goal = MSEgoal;
net.trainParam.min_grad = MinGrad;
[net tr Y E ] = train(net,x,t); % E = t-Y
stopcrit = tr.stop % Validation stop.
numepochs = tr.num_epochs % 60
bestepoch = tr.best_epoch % 54
MSE = tr.perf(bestepoch+1) % 0.0115
MSEa = Ntrneq*MSE/Ndof % 0.0126
R2 = 1-MSE/MSE00 % 0.948
R2a = 1-MSEa/MSE00a % 0.944
assignedclass = vec2ind(Y);
err = assignedclass~=trueclass;
Nerr = sum(err) % 2
PctErr = 100*Nerr/N % 1.33
result = [ H numepochs bestepoch R2 R2a Nerr PctErr]
result = [ 3 60 54 0.948 0.944 2 1.33 ]
% NOTE1: Can use tr to obtain trn/val/tst breakdown
%NOTE2: To imprcve performance try other (e.g.,9 more) random weight initializations. If that doesn't work try 10 random weight initialization trials with H = 4.
Hope this helps.
Thank you for formally accepting my answer
Greg
  4 Comments
Shoumy
Shoumy on 14 Jun 2013
Thanks, Greg. Really helpful. :)

Sign in to comment.

More Answers (2)

Greg Heath
Greg Heath on 14 Jun 2013
Whoops! I made a mistake. If you type the command
tr = tr
you will see that tr.perf, tr.vperf and tr.tperf are the individual MSEs for training, validation and testing. The total MSE is obtained from
MSE = mse(E)
Sorry for the bum steer.
Greg

primrose khaleed
primrose khaleed on 16 May 2014
Hi ...I am new in neural network ...I have folder which store in it images after processing it ...I want to enter this image into neural network...please how can do it...how can consist target and trinning matrix....please help me....

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!