April 2019
Beginner to intermediate
386 pages
11h 20m
English
We can display all of the possible categories and probabilities using the getNumberOfCategories method, as shown next. The getCategory method returns the name of the category and the probabilities array returns the corresponding probability:
for (int i = 0; i < documentCategorizer.getNumberOfCategories(); i++) { System.out.printf("Category: %-4s - %4.2f\n", documentCategorizer.getCategory(i), probabilities[i]);}
When this code is executed, we get the following output:
Category: frog - 0.75Category: rat - 0.25
There is also the getAllResults method, which may be of interest to the reader. It uses the probabilities array and returns a formatted list of the categories and probabilities, as shown next:
System.out.println(documentCategorizer.getAllResults(probabilities)); ...
Read now
Unlock full access