Skip to content
This repository has been archived by the owner on Jan 5, 2021. It is now read-only.

omkarkarande/naive-bayes-classifier

Repository files navigation

naive-bayes-classifier

Generic Naive Bayes classifier buit in python

Usage

First train the classifier python nblearn.py [training_file] [model_file_name]

Then run the classifier on a test set python nbclassify.py [model_file] [testing_file]

The NB.py class is standalone and can be used as is by importing it into your project. Use the functions from the class as shown in the nbtrain.py and nbclassify.py example files.

Notes on the data

The training and testing file data should be in the following format
LABEL FEATURE1:FREQ FEATURE2:FREQ FEATURE3:FREQ ...
LABEL FEATURE1:FREQ FEATURE3:FREQ FEATURE20:FREQ ...

LABEL can be a string as "POSITIVE" or "SPAM"
FEATURES are numeric starting from 1
FREQ is the numeric value of the number of time the corrosponding feature occours in the sample

Example: The positive sample "Hello world . The world is beautiful ." is written as
POSITIVE 1:1 2:2 3:2 4:1 5:1 6:1

where:

  • 1 = "Hello"
  • 2 = "world"
  • 3 = "."
  • 4 = "The"
  • 5 = "is"
  • 6 = "beautiful"

About

Generic Naive Bayes classifier buit in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages