Get count through iteration

Sunny Hot High False No
Overcast Hot High False Yes
Rainy Mild High False Yes

This is a sample of weather dataset.

I need to get the count of the class label without storing them to list,array etc.

While reading the line I should be able to get the NO and YES count. And the comparision cannot be jst no and yes . It can be any number of classes like iris dataset.

Inorder to get the unique class label I used set

Set<String> set = new HashSet<String>();
String classLabel = keys.substring(keys.lastIndexOf(" ") + 1);
set.add(classLabel);

so how will I get the count of each classlabel?

Answers


Your question does lack a bit of info and my answer is making a lot of assumptions, especially since you are putting your classLabel in a Set, I assume you can use other types of collections too, in this case a Map.

private static void weatherForecast() {

    String[] keys = {"Sunny Hot High False No", 
                     "Overcast Hot High False Yes", 
                     "Rainy Mild High False Yes"};

    Map<String, Integer> map = new HashMap<String, Integer>();

    for (String key : keys) {
        String[] split = key.split(" ");
        //Assume your data set is consistent with the 'classLabel' 
        //always the last field.
        String classLabel = split[split.length-1];

        if (map.containsKey(classLabel)) {
            map.put(classLabel, map.get(classLabel) + 1);
        } else {
            map.put(classLabel, 1);
        }
    }

    for (String string : map.keySet()) {
        System.out.println(string + ": " + map.get(string));
    }    
}

Need Your Help

Regex to Match Inner find

html .net regex

I'm trying to match some html list tags &lt;ol&gt;...&lt;/ol&gt; and &lt;ul&gt;...&lt;/ul&gt; using .NET regex. I can match any or both of them using

TCPDF Multicell overlapping

php html pdf tcpdf fpdf

I have 3 different tables in the PDF, created with TCPDF, using MultiCell to display them. They are above eachother and their names are written with writeHTML