https://github.com/chen0040/java-naive-bayes-classifier
Package provides java implementation of naive bayes classifier
https://github.com/chen0040/java-naive-bayes-classifier
classification java naive-bayes-classifier
Last synced: 4 months ago
JSON representation
Package provides java implementation of naive bayes classifier
- Host: GitHub
- URL: https://github.com/chen0040/java-naive-bayes-classifier
- Owner: chen0040
- License: mit
- Created: 2017-05-27T16:30:27.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-03T04:07:27.000Z (over 8 years ago)
- Last Synced: 2023-06-30T13:09:07.075Z (over 2 years ago)
- Topics: classification, java, naive-bayes-classifier
- Language: Java
- Size: 60.5 KB
- Stars: 3
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# java-naive-bayes-classifier
Package provides java implementation of naive bayes classifier (NBC)
[](https://travis-ci.org/chen0040/java-naive-bayes-classifier) [](https://coveralls.io/github/chen0040/java-naive-bayes-classifier?branch=master)
# Features
* Handle both numerical and categorical inputs
# Install
Add the following dependency to your POM file
```xml
com.github.chen0040
java-naive-bayes-classifier
1.0.1
```
# Usage
To train the NBC:
```java
nbc.fit(trainingData);
```
To use NBC for classification:
```java
String predicted = nbc.classify(dataRow);
```
The trainingData object is an instance of data frame consisting of data rows (Please refers to this [link](https://github.com/chen0040/java-data-frame) to find out how to store data into a data frame)
The sample code below shows how to use NBC to solves the classification problem "heart_scale".
```java
InputStream inputStream = new FileInputStream("heart_scale");
DataFrame dataFrame = DataQuery.libsvm().from(inputStream).build();
dataFrame.unlock();
for(int i=0; i < dataFrame.rowCount(); ++i){
DataRow row = dataFrame.row(i);
row.setCategoricalTargetCell("category-label", "" + row.target());
}
dataFrame.lock();
NBC svc = new NBC();
svc.fit(dataFrame);
for(int i = 0; i < dataFrame.rowCount(); ++i){
DataRow row = dataFrame.row(i);
String predicted_label = svc.classify(row);
System.out.println("predicted: "+predicted_label+"\texpected: "+row.categoricalTarget());
}
```