MATLAB Answers

How to compute `AUC` for NN (`patternnet`)?

1 view (last 30 days)
elham
elham on 27 Nov 2020
According to the following code of Matlab, I'm trying to get the AUC of a neural network (patternnet), so I have used the perfcurve function (see the related outputs):
(There are two different classes - labeled 0, 1).
[net, tr] = train(net, xtrain', ytrain'); % xtrain = 64x4; xtest = 7x4;
y_pred = net(xtest');
[~,indicesPredicted] = max(y_pred,[],1);
% output of y_pred (2x7):
% [0.557, 0.557, 0.557, 0.557, 0.788, 0.574, 0.557;
% 0.442, 0.442, 0.442, 0.442, 0.212, 0.425, 0.442]
%
% and so the output of
% indicesPredicted is [1, 1, 1, 1, 1, 1, 1];
score = y_pred';
[~,~,~,AUC] = perfcurve(indicesReal', score(:,2), 1); % indicesReal = [0, 1, 1, 1, 0, 0, 0];
% The output of AUC is 1.
While the result of AUC isn't correct because:
predicted Real
ans = ans =
1 (class 2) 0 (class 1)
1 (class 2) 1 (class 2)
1 (class 2) 1 (class 2)
1 (class 2) 1 (class 2)
1 (class 2) 0 (class 1)
1 (class 2) 0 (class 1)
1 (class 2) 0 (class 1)
How to compute the posterior probabilities (scores) for NN (patternnet) to get AUC?
Also, I have tested the [y_pred, score] = predict(net, xtest); and an error has occurred about predict:
"Error using predict
No valid system or dataset was specified."
I have also seen the related links such as: Link1, Link2, Link3.

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by