Next.
The previous two articles explained that neural networks are a black box with a small sphere (neuron) connected one by one. By changing the connection mode and parameters of neurons, you can implement a compliant neural network. Next we will give an example of a BP neural network to deepen our understanding.
Before explaining this example, let's talk about a neural network solution:
1. Understand the problem to be solved and find the input and output data.
2. Divide the known input and output data into two parts: one is used to train the network, and the other is used to verify whether the training network is useful.
3. Input data is preprocessed and normalized.
4. Create a suitable network, such as BP, sensor, RBF, and tmp2.(In fact, it is to first establish a neural network black box)
5. Set network training parameters, such as training functions, learning functions, and activation functions.
6. Use input/output to train the network.(In fact, the parameters of neurons in the black box are suitable for training and learning)
7. Verify the network using verification data.
8. After verification, I think the network is good and can be used in practice. In the actual application process, I can optimize and reconstruct the model.
Below we begin to illustrate the example of a traditional classification of Flowers (http://en.wikipedia.org/wiki/Iris_flower_data_set): roughly meaning: give you four characteristics of a flower, neural Networks output its varieties (three varieties in total ).
ThereforeInput: Four data, representing the four features of flowers; output: one data, representing the varieties of flowers, respectively, 1, 2, 3 representing three different varieties.
Sample Data: http://files.cnblogs.com/wuguanglei/%E6%95%B0%E6%8D% AE .rar
Specifically, traindata.txtis used as the training data, and testdata.txt is used as the verification data. The MATLAB program code is as follows:
% 0. clear; close all; clc; % 1. read training data [F1, F2, F3, F4, Class] = textread('traindata.txt ',' % F % F', 150); input = [F1, f2, F3, F4] '; % neural network is a column calculated as a sample input, so the matrix needs to be transposed to output = Class'; % 2. normalization of input data [input, se] = mapminmax (input); Mini = Se. xmin; Maxi = Se. xmax; % 3. construct the output data matrix S = length (class); % the output is 1, 2, 3, and 1 0 represents 1; 0 1 represents 2; 0 0 1 indicates 3 Output = zeros (3, S); for I = 1: s output (Class (I), I) = 1; end % 4. create a neural network. Net = newff (MINMAX (inpu T), [70 3], {'logsig ''' 'logsig '}, 'traingdx'); % where 70 indicates 70 neurons in the first layer and 30 neurons in the second layer, the following parameters are set to activate and train functions respectively. % 5. set the training parameter net. trainparam. show = 40; net. trainparam. epochs = 600; net. trainparam. goal = 0.01; net. trainparam. LR = 0.01; % 6. start Training [net, TR, E] = train (net, input, output); % 7. test network [T1 T2 T3 T4 C] = textread('testdata.txt ',' % F % F', 150); testinput = [T1, T2, T3, t4] '; testinput = mapminmax (testinput); y = SIM (net, testinput); % 8. statistical result [S1, S2] = size (y); hitnum = 0; for I = 1: S2 [M, Index] = max (Y (:, I )) if (Index = C (I) hitnum = hitnum + 1; endendsprintf ('recognition rate is % 0.3f % ', 100 * hitnum/s2)
For more information, see the code comments.
Write it here first. It should be enough for beginners.
======================================
Recently, I helped my friends get a public number. at 06:30 every morning, I sent a 60-second speech. If you are interested, please take a look.
No.: wailixs)
QR code:
Chatting about neural networks-writing to beginners (3)