Username Remember Me?
Password   forgot password?
   
   
How to refer/access number of records for specific class using classsizes? 
Posted: 05 August 2010 07:48 AM   [ Ignore ]  
Newbie
Rank
Total Posts:  11
Joined  2010-07-01

Hi,
Thanx for all the help before this. I have used
function classsizes and got the result. In the sample run,
prtools display all the vectors for all the classes.
But I don’t have a clue how to refer/access number of
records for a particular class.
is it something like this?
for i:1:3
disp(C.n(C.lablist(i)));

Thanx.

given sample data

1.3 1
1.4 1
1.5 1
1.6 1
1.66 1
1.7 1
1.75 1
1.8 2
1.82 2
1.83 2
1.84 2
1.85 2
1.88 2
1.89 3
1.9 3
1.92 3
1.93 3
1.94 3
1.95 3
1.99 3

load test
load testlabel
A=dataset(test,testlabel);
[nobs,nvars] = getsize(A);
B=cell(nobs,2);
C=cell(nobs,2);
%
for i = 1 : nvars
B = [A(:,i) A.labels];
%disp(B(:,1:2)); %works
C = B(:,1:2);
[n,lablist]=classsizes(C);
disp(n);
disp(lablist);
end
sample run
7 6 7

1
2
3

Profile
 
 
Posted: 05 August 2010 09:22 AM   [ Ignore ]   [ # 1 ]  
Moderator
RankRankRankRank
Total Posts:  250
Joined  2008-11-08

I don’t get want you want. Your piece of code is confusing to me:

A is a dataset and has already stored the labels for all objects.
What is the reason to create a new dataset B by B = [A(:,i) A.labels]; ?
It overrules the previous declaration B=cell(nobs,2);, which is now superfluous.
It also stores labels as features, which is confusing to me as labels can also be strings.

n gives the classsizes, i.e. the numbers of objects having the same label.
So the class with label 1 has 7 objects, the class with label 2 has 6 objects and
the class with label 3 has 7 objects. In general the class with label lablist(i,:) has
n(i) objects.

The classsizes will not change if you refer to another feature (variable). In this case
nvars = 1, but even if it was 100, the same result would have been obtained for all
variables, e.g.

[A flipud(+A)]; % constructs a dataset with two features
for i=1:nvars
  [n
,lablist] classsizes(B(:,i));
  
disp(n)
  
disp(lablist)
end

generates
7 6 7
1
2
3
7 6 7
1
2
3

The main point to understand is that objects have a single label and may have several features.
If we have 7 horses, 6 cows and 7 dogs, these objects may be given by their weight, height and length.
Also when I just consider the weight, I am referring to the same horses, cows and dogs.

Bob Duin

[ Edited: 05 August 2010 09:36 AM by BobDuin]
Profile
 
 
Posted: 05 August 2010 10:02 AM   [ Ignore ]   [ # 2 ]  
Newbie
Rank
Total Posts:  11
Joined  2010-07-01

Hi,
It is my mistakes to be redundant in declaring the cell array.
I am doing dicretization algorithm for continuous data which will
be used in FS algo later. Since I am doing univariate, so I need
to group each features together with the class. Later, it involves
computing probabilities of each class up to a certain location. So thats
why it seems I am making simple stuffs to be complicated.
Your response did help me with my coding and I appreciate it.

Profile