|
| 1 | +Naive Bayes Classifier implemented in Java. |
| 2 | +================== |
| 3 | + |
| 4 | +Nothing special. It works and is well documented, so you should get it running without wasting too much time searching for other alternatives on the net. |
| 5 | + |
| 6 | +Here is an excerpt from the example. The classifier will classify strings as either positive or negative sentiment. Please refer to the full example for a more detailed documentation. |
| 7 | + |
| 8 | +```java |
| 9 | +Classifier<String, String> bayes = new BayesClassifier<String, String>(); |
| 10 | + |
| 11 | +// Two examples to learn from. |
| 12 | +String[] positiveText = "I love sunny days".split("\\s"); |
| 13 | +String[] negativeText = "I hate rain".split("\\s"); |
| 14 | + |
| 15 | +// Learn by classifying examples. New categories can be added on the fly, |
| 16 | +// when they are first used. |
| 17 | +bayes.learn("positive", Arrays.asList(positiveText)); |
| 18 | +bayes.learn("negative", Arrays.asList(negativeText)); |
| 19 | + |
| 20 | +// Here are two unknown sentences to classify. |
| 21 | +String[] unknownText1 = "today is a sunny day".split("\\s"); |
| 22 | +String[] unknownText2 = "there will be rain".split("\\s"); |
| 23 | + |
| 24 | +System.out.println( // will output "positive" |
| 25 | + bayes.classify(Arrays.asList(unknownText1)).getCategory()); |
| 26 | +System.out.println( // will output "negative" |
| 27 | + bayes.classify(Arrays.asList(unknownText2)).getCategory()); |
| 28 | + |
| 29 | +// Get more detailed classification result. |
| 30 | +((BayesClassifier<String, String>) bayes).classifyDetailed( |
| 31 | + Arrays.asList(unknownText1)); |
| 32 | + |
| 33 | +// Change the memory capacity. |
| 34 | +bayes.setMemoryCapacity(500); |
| 35 | +``` |
| 36 | + |
| 37 | +Forgetful learning |
| 38 | +------------------ |
| 39 | + |
| 40 | +This classifier is forgetful. This means, that the classifier will forget recent classifications it uses for future classifications after - defaulting to 200 - classifications learned. |
| 41 | +This will ensure, that the classifier can react to ongoing changes in the user's habbits. |
| 42 | + |
| 43 | +Possible Performance issues |
| 44 | +------------------ |
| 45 | + |
| 46 | +Performance improvements, I am currently thinking of: |
| 47 | + |
| 48 | +- Store the natural logarithms of the feature probabilities and add them together instead of multiplying the probability numbers |
| 49 | + |
| 50 | +The MIT License (MIT) |
| 51 | +------------------ |
| 52 | + |
| 53 | +Copyright (c) 2012 Philipp Nolte |
| 54 | + |
| 55 | +Permission is hereby granted, free of charge, to any person obtaining a copy |
| 56 | +of this software and associated documentation files (the "Software"), to deal |
| 57 | +in the Software without restriction, including without limitation the rights |
| 58 | +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 59 | +copies of the Software, and to permit persons to whom the Software is |
| 60 | +furnished to do so, subject to the following conditions: |
| 61 | + |
| 62 | +The above copyright notice and this permission notice shall be included in |
| 63 | +all copies or substantial portions of the Software. |
| 64 | + |
| 65 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 66 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 67 | +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 68 | +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 69 | +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 70 | +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 71 | +THE SOFTWARE. |
0 commit comments