GithubHelp home page GithubHelp logo

kipsangmarion / streaming-naive-bayes-classifier Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 2 KB

A Naive Bayes Classifier to handle a large stream of data

Jupyter Notebook 100.00%
classification machine-learning naive-bayes-classifier python

streaming-naive-bayes-classifier's Introduction

Streaming Naive Bayes Classifier

Overview

This Python code implements a streaming version of the Naive Bayes classifier. The algorithm is designed to handle large datasets in a streaming fashion, updating its model incrementally as new data arrives. The Naive Bayes classifier is a probabilistic model based on Bayes' theorem and is commonly used for text classification, spam filtering, and other tasks.

Problem Solved

The main goal of this algorithm is to provide a scalable and memory-efficient solution for Naive Bayes classification when dealing with large databases. It allows for the model to be updated with new instances without needing to store the entire dataset in memory. The code provides a foundation for real-time classification tasks, adapting to the continuous stream of incoming data.

Usage

  1. Initialization:

    • Create an instance of the StreamingNaiveBayes class by specifying the classes for classification.
    classes = ['spam', 'ham']
    model = StreamingNaiveBayes(classes)
  2. Updating the Model:

    • Update the model with new instances and their corresponding class labels using the update_model method.
    instance1 = {'word1': 'hello', 'word2': 'world'}
    model.update_model(instance1, 'ham')
    
    instance2 = {'word1': 'discount', 'word2': 'offer'}
    model.update_model(instance2, 'spam')
  3. Updating Class Probabilities:

    • After updating the model, use the update_class_probabilities method to recalculate class probabilities.
    model.update_class_probabilities()
  4. Making Predictions:

    • Use the predict method to make predictions for new instances.
    new_instance = {'word1': 'hello', 'word2': 'world'}
    prediction = model.predict(new_instance)
    print("Predicted class:", prediction)

Notes

  • This implementation assumes feature independence, which is a naive but often effective assumption.
  • The code includes basic smoothing for unseen feature values.

Feel free to customize and expand the program to better fit your specific use case.

streaming-naive-bayes-classifier's People

Contributors

kipsangmarion avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

sandy4321

streaming-naive-bayes-classifier's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.