divide training set into validation but test on a different set in NN
조회 수: 4 (최근 30일)
이전 댓글 표시
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
Greg Heath
2018년 11월 16일
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
답변 (1개)
Greg Heath
2018년 11월 17일
I have an answer
BUT FOR SOME REASON, CANNOT PASTE IT INTO THE ANSWER BOX
HELP !!!
heath@alumni.brown.edu
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!