Giter VIP home page Giter VIP logo

documer's Introduction

Documer

Bayes algorithm implementation in PHP for auto document classification.

Concept

every document has key words e.g. Margaret Thatcher

every document has a label e.g. Politics

Suppose, that in every document there are key words all starting with an uppercase letter. We store these words in our DB end every time we need to guess a document against a particular label, we use Bayes algorithm.

Let's clear that out:

Training:

First, we tokenize the document and keep only our key words (All words starting with an uppercase letter) in an array. We store that array in our DB.

Guessing:

This is very simple. Again, we parse the document we want to be classified and create an array with the key words. Here is the pseudo code:

for every label in DB
	for every key word in document
		P(label/word) = P(word/label)P(label) /	( P(word/label)P(label) + (1 - P(word/label))(1 - P(label)) )

Usage

Install through composer

"require": {
    "kbariotis/documer": "dev-master"
  },

Instantiate

Pass a Storage Adapter object to the Documer Constructor.

$documer = new Documer\Documer(new \Documer\Storage\Memory());

Train

$documer->train('politics', 'This is text about Politics and more');
$documer->train('philosophy', 'Socrates is an ancent Greek philosopher');
$documer->train('athletic', 'Have no idea about athletics. Sorry.');
$documer->train('athletic', 'Not a clue.');
$documer->train('athletic', 'It is just not my thing.');

Guess

$scores = $documer->guess('What do we know about Socrates?');

$scores will hold an array with all labels of your system and the posibbility which the document will belong to each label.

Storage Adapters Implement Documer\Storage\Adapter to create your own Storage Adapter.

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.