what is the value of predicted and actual?
4 次查看(过去 30 天)
显示 更早的评论
MANIMEGALAI SELVARAJ
2017-2-19
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];
1 个评论
采纳的回答
Star Strider
2017-2-19
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 个评论
oza san
2017-5-12
编辑:oza san
2017-5-12
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
2017-5-12
You must be certain your ‘ACTUAL’ and ‘d’ vectors are the same sizes (same number of rows and columns in each).
oza san
2017-5-12
Dear Star thank you for your fast replay.ok.i will try that way but since ACTUAL is the value of the training sample how it could be equal with testing sample which is 20% of the training sample?
oza san
2017-5-12
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.
oza san
2017-5-14
Dear sir,here i am again i need to extract a word from a sentence in an image using vertical projection profile mind you if you have some ample codes?
Star Strider
2017-5-14
Post this as a new Question.
Image processing is not an area of my expertise.
I cannot help you with it.
oza san
2017-5-15
编辑:oza san
2017-5-15
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
2017-5-15
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
2017-5-15
编辑:oza san
2017-5-15
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
2017-5-15
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
2017-5-15
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
2017-5-15
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
oza san
2017-5-15
here is what i get Name Size Bytes Class Attributes
c 200x1 1600 double
Name Size Bytes Class Attributes
d 200x1 22800 cell
Star Strider
2017-5-15
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
oza san
2017-5-15
i thought that both actual and predicted value are structure so i tried to convert to cell array.but now i ignore.
oza san
2017-5-15
" Undefined operator '==' for input arguments of type 'cell'."
tp = sum(c(idx) == d(idx));what is wrong with this one?
oza san
2017-5-15
Dear sir i make you too busy let me see it by myself and if i can't i will be back.
Nowshin Jenny
2018-12-19
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?
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)