Closed tom-adsfund closed 10 years ago
There you go! Have fun! If there are any issues, please let me know. I haven't used and updated this code for nearly two years, but would be happy to work on it again.
Excellent, thanks for doing that, and I'll let you know if I have any problems.
I found your java-naive-Bayes-classifier very useful and interesting. However, I have a question about applying this classifier with other feature type values. Is it possible to construct this Bayes naive classifier (this package) using numerical values (integer or float numbers) rather than textual values?Do I need to modify codes to achieve this goal? Thanks.
The base Classifier<T, K>
is generic and can handle virtually any class for features and categories. For example:
Classifier<Integer, String> ClassifierWithIntegerFeature =
new BayesClassifier<Integer, String>();
ArrayList<Integer> integerFeatures = new ArrayList<Integer> {{
add(new Integer(1));
add(new Integer(1));
add(new Integer(1));
add(new Integer(1));
}};
ClassifierWithIntegerFeature.learn("Ones", integerFeatures);
Classifier<MyClass, String> ClassifierWithMyClassFeature =
new BayesClassifier<MyClass, String>();
ArrayList<MyClass> myClassFeatures = new ArrayList<MyClass> {{
add(new MyClass("ONE"));
add(new MyClass("ONE"));
add(new MyClass("ONE"));
add(new MyClass("ONE"));
}};
ClassifierWithMyClassFeature.learn("Ones", myClassFeatures);
Because the base Classifier<T, K>
class internally uses hashtables, both the feature and category class need to provide hashCode()
and equals()
methods.
Also note, that you have to use Wrapper-Classes for primitive types. So use Integer
instead of int
and Float
instead of float
. Find out more about generics here.
Please could you add a (MIT?) license?
Thanks