Question
I wrote a code for classification, using a” patternnet “neural network to classify a dataset which is 2D two spiral dataset, all my data were 40 in two classes each class population was 20, I manually separated it in two parts, part one training and validation and part two testing, so 32 out of 40 is associated in training and validation phase and 8 for testing, the separation process is randomly, I give data of part one to the net 90% for training, 10% for validation. net = patternnet(70); net.divideParam.trainRatio=0.9 net.divideParam.valRatio=0.1 net.divideParam.testRatio=0 then I use the trained net for testing the data of part two, my problem is no matter how many neurons I use, the classification result is perfect , over fitting doesn’t happen , even if I use 70 neurons , how such thing is possible? I should work with neural networks which are capable of over fitting easily, I use small size data sets which are distributed in a complex pattern, like spirals , or banana-shaped data sets , I would like to have them in higher dimension space but unfortunately I couldn’t generate them in higher spaces .
Related Questions
Expert Answer
Kshitij Singh
PhD Expert
Answered Nov 20, 2025
You misunderstand. The sin is not overfitting. It is overtraining a net that is overfit.
Overfitting happens when there are more unknown weights, Nw, to estimate than there are training equations, Ntrneq.
This typically means that Nw-Ntrneq weights can have ARBITRARY values and the remaining Ntrneq weights can be chosen to EXACTLY solve the training equations.
The problem with this is that, for serious work, nets must be designed to perform well on unseen operational data. However, that usually does not happen when some of the weights are arbitrary.
There are three methods you can use separately or in combination with MATLAB to mitigate this problem: Non-overfitting, Validation Stopping and Regularization:
1. Non-overfitting: Make sure that Ntrneq >= Nw 2. Validation stopping (a default data division that prevents overtraining an overfit net): total = design + test design = training + validation non-design = test total = training + non-training non-training = validation + testing
Use a non-training validation design set that stops training set weight estimation when performance on the non-training validation design subset fails to increase for a fixed number (default = 6) of epochs.
3. Regularization: Minimize the weighted sum of mean-square-error and mean-squared-weights via either
net.performParam.regularization = a ;% 0 < a < 1
or
net.trainFcn = 'trainbr';
Details can be obtained by searching for
a. Documentation on Validation stopping and regularization b. Relevant posts in both the NEWSGROUP and ANSWERS. Suitable search words are overfitting, overtraining, regularization, trainbr and validation stopping
Have a different question? Ask here