Lecture 7 - Perceptrons and Multi-Layer Feedforward Neural Networks Using Matlab Part 3
Lecture 7 - Perceptrons and Multi-Layer Feedforward Neural Networks Using Matlab Part 3
Qadri Hamarsheh
Build a neural network that can estimate the median price of a home
described by thirteen attributes:
1. crime rate per town
2. Proportion of residential land zoned for lots over 25,000 sq. ft.
3. proportion of non-retail business acres per town
4. 1 if tract bounds Charles river, 0 otherwise
5. Nitric oxides concentration
6. Average number of rooms
7. Proportion of owner-occupied units built prior to 1940
8. Weighted distances to five Boston employment centres
9. Index of accessibility to radial highways
10. -tax rate per $10,000
11. Pupil-teacher ratio by town
12. 1000(Bk - 0.63)^2
13. Percent lower status of the population
Create a neural network which not only estimates the known targets given
known inputs, but can generalize to estimate outputs for inputs that were not
used to design the solution: It is a fitting problem.
Why Neural Networks?
Neural networks are very good solution for solving the function fit
problems with non-linear nature.
The thirteen attributes are the inputs to a neural network, and the
median home price is the target.
Preparing the Data
Load the dataset.
[P, T] = house_dataset;
The samples are automatically divided into training, validation and test
sets.
The training set is used to teach the network. Training continues as
long as the network continues improving on the validation set.
The test set provides a completely independent measure of network
accuracy.
[net, tr] = train (net, P, T); % tr is the training record information
nntraintool % to display the training tool window
2
Dr. Qadri Hamarsheh
Performance is shown for each of the training, validation and test sets.
I. The mean squared error of the trained neural network is used to how well
the network will do when applied to data from the real world.
testP = P (:, tr.testInd);
testT = T (:, tr.testInd);
testA = net ( testP);
perf = mse (net, testT, testA);
perf =
19.3315
3
Dr. Qadri Hamarsheh
III. Error histogram is used to show how the error sizes are distributed.
Typically most errors are near zero, with very few errors far from that.
To display the Error histogram, we can use either:
“Error histogram” button in the training tool.
Call ploterrhist function:
E = T - A;
ploterrhist (E);
Truth table:
4
Dr. Qadri Hamarsheh
Solution:
P = [0 0 1 1; 0 1 0 1]; % training inputs, p = [p1; p2]
T = [0 0 0 1]; % targets
net = newp ([0 1; 0 1], 1);
net = train (net, P, T);
a = sim (net, P);
a=
0001
T=
0001
3) Pattern Classification
timg1 = [1 1 0 1 0 1 0 1 0 0 1 0 ]';
timg3 = [1 0 1 0 1 0 0 0 1 1 0 1]';
timg2 = [1 0 1 0 1 1 0 0 0 1 0 1]';
P = [image1 image2 image3 image4];
T = [0 1 0 1];
net = newp (minmax(P), 1);
5
Dr. Qadri Hamarsheh