How to load own data set into neural network?

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.

 Akzeptierte Antwort

Greg Heath
Greg Heath am 13 Jun. 2013

1 Stimme

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 Kommentare

Thanks so much Greg for your long and detailed answer. Really appreciate it. So, to reconfirm the method, I have to enter/load x and t before using datasets?
x = load ('Bloodratio.mat');
t = load ('BloodratioTarget.mat');
[ x, t ] = iris_dataset;
[ I N ] = size(x)
[ O N ] = size(t)
Like this? Sorry for asking such simple questions..I really am a newbie. Thank you for bearing with me. :)
Greg Heath
Greg Heath am 14 Jun. 2013
Bearbeitet: Greg Heath am 14 Jun. 2013
Delete the iris_dataset line. That nndata was just used for demonstration purposes.
help nndatasets
Shoumy
Shoumy am 14 Jun. 2013
Thanks, Greg. Really helpful. :)
what is n in the code?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Greg Heath
Greg Heath am 14 Jun. 2013

1 Stimme

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 am 16 Mai 2014

0 Stimmen

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....

Kategorien

Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by