divide training set into validation but test on a different set in NN

4 visualizaciones (últimos 30 días)
prince sniper
prince sniper el 14 de Nov. de 2018
Editada: prince sniper el 18 de Nov. de 2018
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 comentarios
Greg Heath
Greg Heath el 16 de Nov. de 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
prince sniper
prince sniper el 17 de Nov. de 2018
Editada: prince sniper el 17 de Nov. de 2018
Thank you for your answer. Actually I don't have a lot of time. I have added the code I am using so you can see what probably I am missing.
It's an important project, I want to compare many training functions (testing many parameters in trainFcn). But, I am suck in this problem: Since I have a seprarate testing set. I want to:
  • Use 20% of training data as a validation set
  • Use the testing set (X_Test, Y_Test) for testing. Meaning, I want to use divideFcn to divide data into two subsets (Training and validation) and use X_test and Y_test for testing. I hope this is clear to you.
I also appreciate any feedback you have on my code. Those few lines of code took a lot of reading.

Iniciar sesión para comentar.

Respuestas (1)

Greg Heath
Greg Heath el 17 de Nov. de 2018
I have an answer
BUT FOR SOME REASON, CANNOT PASTE IT INTO THE ANSWER BOX
HELP !!!
heath@alumni.brown.edu

Categorías

Más información sobre Sequence and Numeric Feature Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by