Naive Bayes Classifier

Naive Bayes Classifier that handles both numerical and categorical inputs

License

License

MIT
Categories

Categories

Java Languages
GroupId

GroupId

com.github.chen0040
ArtifactId

ArtifactId

java-naive-bayes-classifier
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Naive Bayes Classifier
Naive Bayes Classifier that handles both numerical and categorical inputs
Project URL

Project URL

https://github.com/chen0040/java-naive-bayes-classifier
Source Code Management

Source Code Management

https://github.com/chen0040/java-naive-bayes-classifier

Download java-naive-bayes-classifier

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.chen0040/java-naive-bayes-classifier/ -->
<dependency>
    <groupId>com.github.chen0040</groupId>
    <artifactId>java-naive-bayes-classifier</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.chen0040/java-naive-bayes-classifier/
implementation 'com.github.chen0040:java-naive-bayes-classifier:1.0.1'
// https://jarcasting.com/artifacts/com.github.chen0040/java-naive-bayes-classifier/
implementation ("com.github.chen0040:java-naive-bayes-classifier:1.0.1")
'com.github.chen0040:java-naive-bayes-classifier:jar:1.0.1'
<dependency org="com.github.chen0040" name="java-naive-bayes-classifier" rev="1.0.1">
  <artifact name="java-naive-bayes-classifier" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.chen0040', module='java-naive-bayes-classifier', version='1.0.1')
)
libraryDependencies += "com.github.chen0040" % "java-naive-bayes-classifier" % "1.0.1"
[com.github.chen0040/java-naive-bayes-classifier "1.0.1"]

Dependencies

compile (3)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.20
org.slf4j : slf4j-log4j12 jar 1.7.20
com.github.chen0040 : java-data-frame jar 1.0.9

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.6

test (10)

Group / Artifact Type Version
org.testng : testng jar 6.9.10
org.hamcrest : hamcrest-core jar 1.3
org.hamcrest : hamcrest-library jar 1.3
org.assertj : assertj-core jar 3.5.2
org.powermock : powermock-core jar 1.6.5
org.powermock : powermock-api-mockito jar 1.6.5
org.powermock : powermock-module-junit4 jar 1.6.5
org.powermock : powermock-module-testng jar 1.6.5
org.mockito : mockito-core jar 2.0.2-beta
org.mockito : mockito-all jar 2.0.2-beta

Project Modules

There are no modules declared in this project.

java-naive-bayes-classifier

Package provides java implementation of naive bayes classifier (NBC)

Build Status Coverage Status

Features

  • Handle both numerical and categorical inputs

Install

Add the following dependency to your POM file

<dependency>
  <groupId>com.github.chen0040</groupId>
  <artifactId>java-naive-bayes-classifier</artifactId>
  <version>1.0.1</version>
</dependency>

Usage

To train the NBC:

nbc.fit(trainingData);

To use NBC for classification:

String predicted = nbc.classify(dataRow);

The trainingData object is an instance of data frame consisting of data rows (Please refers to this link 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".

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());
}

Versions

Version
1.0.1