divide training set into validation but test on a different set in NN
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am building a neural network classifier using matlab. For this I have the following dataset.
size(X_Train): 125973 x 122
size(Y_Train): 125973 x 1
size(X_Test): 22543 x 122
size(Y_test): 22543 x 1
As you can see, I already have a testing set I can use. I want to use %20 of my training data set for validation and X_Test and Y_Test for testing. So after constructing my neural network (which I called net) using the network function. I divided the training set using this code:
% divide data into training and test
net.divideParam.trainRatio = 80/100; % 80% training
net.divideParam.valRatio = 20/100; % 20% validation set
I don't want to use
net.divideParam.testRatio
to divide the training set, but I don't know how to tell the network to use X_Test and Y_Test for testing. Any help?
I also have an error, it seems that I can't divide the data without using the parameter net.divideFcn(). However, for every value I use in the net.divideFcn(). I get the following error:
Error using network/subsref (line 198)
Index exceeds matrix dimensions.
Error in NN (line 32)
net.divideFcn('dividerand');
Edit:
Here is the code I am using.
%% Create the neural network
% 1, 2: ONE input, TWO layers (one hidden layer and one output layer)
% [1; 1]: both 1st and 2nd layer have a bias node
% [1; 0]: the input is a source for the 1st layer
% [0 0; 1 0]: the 1st layer is a source for the 2nd layer
% [0 1]: the 2nd layer is a source for your output
net = network(1, 2, [1; 1], [1; 0], [0 0; 1 0], [0 1]);
net.inputs{1}.size = 122; % input size
net.layers{1}.size = 25; % hidden layer size
net.layers{2}.size = 1; % output layer size
%% Transfer function in layers
net.layers{1}.transferFcn = 'logsig';
net.layers{2}.transferFcn = 'logsig';
%% divide data into training and test
net.divideFcn('divideint');
net.divideParam.trainRatio = 80/100; % 80% training
net.divideParam.valRatio = 20/100; % 20% validation set
%% Training functions
net.trainFcn = 'trainscg'; %Scaled conjugate gradient backpropagation
%% Train the neural network
[net,TR] = train(net,X_training,Y_training);
%plotperform(TR);
%view(net);
%nntraintool
%% Test the Neural Network
outputs = net(X_training);
errors = gsubtract(Y_training,outputs);
performance = perform(net,targetData,outputs);
For the error I used to have. It's so simple, Use:
net.divideFcn = 'divideint';
Instead of
net.divideFcn = 'divideint';
But I am still trying to find a solution for the other issue.
2 commentaires
Greg Heath
le 16 Nov 2018
Not enough code to determine EXACTLY what you did.
If this is serious work and you have enough time, it would be worthwhile
to determine the number of independent dimensions.
Typically, 35 random samples for every independent dimension is sufficient.
However, you might want to determine the independent dimensionality and
form subsets with ~100 random samples per dimension.
Otherwise just use the apparent dimensionality of 122. However, since you
have so much data, Idividing the dataset into subsets with ~ 100
random samples per dimension is not unreasonable.
So, you have at least 10 times more data than necessary.
Hope this helps.
Greg
Réponses (1)
Greg Heath
le 17 Nov 2018
I have an answer
BUT FOR SOME REASON, CANNOT PASTE IT INTO THE ANSWER BOX
HELP !!!
heath@alumni.brown.edu
0 commentaires
Voir également
Catégories
En savoir plus sur Sequence and Numeric Feature Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!