Department of Mathematics and Computer Science

www.univ-soukahras.dz/en/dept/mi

Module: Apprentissage automatique II

  1. Information
  2. Questions

Given the following dataset in Matlab, find the different classes and number of instances

0 votes

Given the following dataset in Matlab, Write a function in Matlab to find the different classes and number of instances per class:

data=[
{'sunny'};
{'sunny'};
{'overcast'};
{'sunny'};
{'sunny'};
{'rain'};
{'sunny'};
{'rain'};
{'overcast'};
{'sunny'};
{'rain'};
{'rain'};
]

Asked on 11:12, Monday 18 Nov 2019 By Imed BOUCHRIKA
In Apprentissage automatique II


Answers (1)




Answer (1)

0 votes

1/ the function

============================================

function [classes, instancesN] = findClasses(dataset)

m_map = containers.Map();

[rows, columns] = size(dataset);

for i=1:rows

     if m_map.isKey(dataset{i,1})

            m_map(dataset{i,1}) = m_map(dataset{i,1})+1;

     else

            m_map(dataset{i,1}) = 1;

     end

end

classes = m_map.keys();

instancesN = m_map.values();

for k=1:length(classes)
     x = classes{k};
     i = num2str(instancesN{k});
     strcat("Class: '",x,"' has: ",i," instance(s)")
end

=============================================

Execution:

test

 

Answered on 16:41, Monday 18 Nov 2019 by abdennour redjaibia (282 points)
In Apprentissage automatique II



Do you have an answer ?