www.gusucode.com > nnet 案例源码 matlab代码程序 > nnet/RefPlotconfusionExample.m

    %% Plot Confusion Matrix
% This example shows how to train a pattern recognition network and plot its accuracy.
%% 
% Load the sample data.
[x,t] = cancer_dataset;
%%
% |cancerInputs| is a 9x699 matrix defining nine attributes of 699
% biopsies. |cancerTargets| is a 2x966 matrix where each column indicates a
% correct category with a one in either element 1 (benign) or element 2
% (malignant). For more information on this dataset, type |help
% cancer_dataset| in the command line.
%%
% Create a pattern recognition network and train it using the sample data.
net = patternnet(10);
net = train(net,x,t);
%%
% Estimate the cancer status using the trained network, |net| .
y = net(x);
%%
% Plot the confusion matrix. 
plotconfusion(t,y)
%%
% In this figure, the first two diagonal cells show the number and
% percentage of correct classifications by the trained network. For example
% 446 biopsies are correctly classifed as benign. This corresponds to
% 63.8% of all 699 biopsies. Similarly, 236 cases are
% correctly classified as malignant. This corresponds to 33.8% of all biopsies.
%
% 5 of the malignant biopsies are incorrectly classified as benign and this
% corresponds to 0.7% of all 699 biopsies in the data. Similarly, 12 of the
% benign biopsies are incorrectly classified as malignant and this
% corresponds to 1.7% of all data.
%
% Out of 451 benign predictions, 98.9% are correct and 1.1% are wrong. Out
% of 248 malignant predictions, 95.2% are correct and 4.8% are wrong. Out
% of 458 benign cases, 97.4% are correctly predicted as benign and
% 2.6% are predicted as malignant. Out of 241 malignant cases, 97.9%
% are correctly classified as malignant and 2.1% are
% classified as benign.
%
% Overall, 97.6% of the predictions are correct and 2.4% are wrong
% classifications.