You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
what is the value of predicted and actual?
3 views (last 30 days)
Show older comments
function EVAL = Evaluate(ACTUAL,PREDICTED)
% This fucntion evaluates the performance of a classification model by
% calculating the common performance measures: Accuracy, Sensitivity,
% Specificity, Precision, Recall, F-Measure, G-mean.
% Input: ACTUAL = Column matrix with actual class labels of the training
% examples
% PREDICTED = Column matrix with predicted class labels by the
% classification model
% Output: EVAL = Row matrix with all the performance measures
idx = (ACTUAL()==1);
p = length(ACTUAL(idx));
n = length(ACTUAL(~idx));
N = p+n;
tp = sum(ACTUAL(idx)==PREDICTED(idx));
tn = sum(ACTUAL(~idx)==PREDICTED(~idx));
fp = n-tn;
fn = p-tp;
tp_rate = tp/p;
tn_rate = tn/n;
accuracy = (tp+tn)/N;
sensitivity = tp_rate;
specificity = tn_rate;
precision = tp/(tp+fp);
recall = sensitivity;
f_measure = 2*((precision*recall)/(precision + recall));
gmean = sqrt(tp_rate*tn_rate);
EVAL = [accuracy sensitivity specificity precision recall f_measure gmean];
Accepted Answer
Star Strider
on 19 Feb 2017
From the documenbtation:
% Input: ACTUAL = Column matrix with actual class labels of the training
% examples
% PREDICTED = Column matrix with predicted class labels by the
% classification model
I would assume that ‘matrix’ is ‘vector’ here. The ‘ACTUAL’ values are whatever the original classifications are, and the ‘PREDICTED’ the results of your classifier. The values likely depend on the original ‘correct’ classifications and your classifier output.
31 Comments
oza san
on 12 May 2017
Edited: oza san
on 12 May 2017
dear Star i have been trying to use the above code but i stack with an error "index exceeds matrix dimensions. Error in Evaluate1 (line 21) tp = sum(ACTUAL(idx)==d(idx));" what can i do?
if true
newX=load('C:\Users\sam\Desktop\dataset\pred.mat');%to load the classifier output!
d = struct2cell(newX); % to change its format from struct to cell array
ACTUAL = zeros(2000,1); the orginal value
ACTUAL(1:1000) = 0;% setfirst 1000 row as negative sapmle
ACTUAL(1001:end) = 1; % set the rest as postive sample
the rest of the code is as it is!!
end
Star Strider
on 12 May 2017
You must be certain your ‘ACTUAL’ and ‘d’ vectors are the same sizes (same number of rows and columns in each).
Star Strider
on 12 May 2017
Use the testing sample and the classifications from it for both vectors.
oza san
on 12 May 2017
ya i test it manually and works fine.before i give the the test sample for the classifier i set the values for it[0 and 1]. then i get the classifier output with the same column number finally i use both of them for evaluation.
Star Strider
on 12 May 2017
If this helped you solve your problem, please Vote for my Answer!
Star Strider
on 12 May 2017
Thank you!
As always, my pleasure!
Star Strider
on 14 May 2017
Post this as a new Question.
Image processing is not an area of my expertise.
I cannot help you with it.
Star Strider
on 14 May 2017
As always, my pleasure!
oza san
on 15 May 2017
Edited: oza san
on 15 May 2017
Dear Sir, i tried to load my actual and predicted values to calculate performance measures but i can't load the data.i get an error"Undefined operator '==' for input arguments of type 'cell'."!! actually when i give the actual manually it woks fine!!!the problem is it can not load the data found in .mat file. what can i do?
if true
% code
ACTUAL=load('C:\Users\sam\Desktop\dataset\ACTUAL.mat');%load actual
pred=load('C:\Users\sam\Desktop\dataset\pred.mat');%load predicted
c = struct2cell(ACTUAL);%change the struct to cell
d = struct2cell(pred);%change the struct to cell
idx = (c()==1);
p = length(c(idx));
n = length(c(~idx));
N = p+n;
tp = sum(c(idx)==d(idx));
tn = sum(c(~idx)==d(~idx));
fp = n-tn;
end
Star Strider
on 15 May 2017
The only place I see that is in your ‘idx’ assignment.
This should work:
c = {1 2 6 1 3 7 9 1}; % Create Test Data
idx = cellfun(@eq, c, mat2cell(ones(size(c)), 1, ones(size(c))), 'Uni',0);
idx = [idx{:}];
oza san
on 15 May 2017
Edited: oza san
on 15 May 2017
i cam up with an error"Input arguments, D1 through D2, must sum to each dimension of the input matrix size, [200 1].'"
if true
% code
c= zeros(200,1); creating test data
c(1:end) = 1;
idx = cellfun(@eq, c, mat2cell(ones(size(c)), 1, ones(size(c))), 'Uni',0);
idx = [idx{:}]
end
Star Strider
on 15 May 2017
You didn’t tell me what size ‘c’ is.
Try this:
idx = cellfun(@eq, c, mat2cell(ones(size(c)), ones(size(c)), 1), 'Uni',0);
Star Strider
on 15 May 2017
This works correctly for me:
c = {1 2 6 1 3 7 9 1}'; % Create Test Data
idx = cellfun(@eq, c, mat2cell(ones(size(c)), ones(size(c)), 1), 'Uni',0)
idx = [idx{:}]
I cannot determine what the problem may be with respect to your code.
I am using R2017a. There could be version differences in the way the functions work.
Star Strider
on 15 May 2017
I thought ‘c’ was already a cell array. That was the original problem.
What is the result when you run this from your Command Window (or script):
whos c
Star Strider
on 15 May 2017
I don’t understand that in the context of these earlier assignments:
c = struct2cell(ACTUAL);%change the struct to cell
d = struct2cell(pred);%change the struct to cell
Star Strider
on 15 May 2017
I’m lost.
If ‘c’ is a double array, your original:
idx = c == 1;
should work.
oza san
on 16 May 2017
Edited: oza san
on 16 May 2017
Dear sir.here i am to say thank you!!!just i change the cell array to double matrix using "d = str2double(d);" and it works fine.even though am not sure other commands(performance measurements) will not be affected.
Star Strider
on 16 May 2017
My pleasure.
Nowshin Jenny
on 19 Dec 2018
Dear sir, after using this command in my code for EEG signal classification, I got following error-
"Function definitions are not permitted in this context."
How can i solve it?
More Answers (0)
See Also
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)