Département d'Informatique

https://www.univ-soukahras.dz/fr/dept/cs

Matière: Apprentissage automatique II

  1. Information
  2. Questions
  3. E-Learning

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'};
]

Posté le 11:12, Monday 18 Nov 2019 By Imed BOUCHRIKA
In Apprentissage automatique II


Réponses (1)




Réponse (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

 

Posté le 16:41, Monday 18 Nov 2019 by abdennour redjaibia (282 points)
In Apprentissage automatique II



Avez vous une réponse ?