Generate pattern recognition network
returns a pattern recognition neural network with a hidden layer size of
net = patternnet(
hiddenSizes, a training function, specified by
trainFcn, and a performance function, specified by
Pattern recognition networks are feedforward networks that can be trained to classify
inputs according to target classes. The target data for pattern recognition networks should
consist of vectors of all zero values except for a 1 in element
i is the class they are to represent.
Construct and Train a Pattern Recognition Neural Network
This example shows how to design a pattern recognition network to classify iris flowers.
Load the training data.
[x,t] = iris_dataset;
Construct a pattern network with one hidden layer of size 10.
net = patternnet(10);
Train the network
net using the training data.
net = train(net,x,t);
View the trained network.
Estimate the targets using the trained network.
y = net(x);
Assess the performance of the trained network. The default performance function is mean squared error.
perf = perform(net,t,y)
perf = 0.0302
classes = vec2ind(y);
hiddenSizes — Size of the hidden layers
10 (default) | row vector
Size of the hidden layers in the network, specified as a row vector. The length of the vector determines the number of hidden layers in the network.
Example: For example, you can specify a network with 3 hidden layers, where the first
hidden layer size is 10, the second is 8, and the third is 5 as follows:
The input and output sizes are set to zero. The software adjusts the sizes of these during training according to the training data.
trainFcn — Training function name
'trainscg' (default) |
'trainlm' | ...
Training function name, specified as one of the following.
Scaled Conjugate Gradient
Conjugate Gradient with Powell/Beale Restarts
Fletcher-Powell Conjugate Gradient
Polak-Ribiére Conjugate Gradient
One Step Secant
Variable Learning Rate Gradient Descent
Gradient Descent with Momentum
Example: For example, you can specify the variable learning rate gradient descent
algorithm as the training algorithm as follows:
For more information on the training functions, see Train and Apply Multilayer Shallow Neural Networks and Choose a Multilayer Neural Network Training Function.
performFcn — Performance function
Performance function. The default value is
This argument defines the function used to measure the network’s performance. The performance function is used to calculate network performance during training.
For a list of functions, in the MATLAB command window, type
net — Pattern recognition network
Pattern recognition neural network, returned as a