PHPackages                             assisted-mindfulness/naive-bayes - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. assisted-mindfulness/naive-bayes

ActiveLibrary

assisted-mindfulness/naive-bayes
================================

Naive Bayes classifier algorithm

1.0.0(7mo ago)44535.6k↓47.9%3MITPHPPHP ^8.1CI passing

Since Mar 11Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/Assisted-Mindfulness/naive-bayes)[ Packagist](https://packagist.org/packages/assisted-mindfulness/naive-bayes)[ RSS](/packages/assisted-mindfulness-naive-bayes/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (5)Versions (10)Used By (0)

Naive Bayes
===========

[](#naive-bayes)

[![Tests](https://github.com/Assisted-Mindfulness/naive-bayes/actions/workflows/phpunit.yml/badge.svg)](https://github.com/Assisted-Mindfulness/naive-bayes/actions/workflows/phpunit.yml)

This PHP package for Naive Bayes works by looking at a training set and making a guess based on that set. It uses simple statistics and a bit of math to calculate the result.

What can I use this for?
------------------------

[](#what-can-i-use-this-for)

You can use this for categorizing any text content into any arbitrary set of **categories**. For example:

- is an email **spam**, or **not spam** ?
- is a news article about **technology**, **politics**, or **sports** ?
- is a piece of text expressing **positive** emotions, or **negative** emotions?

Installation
------------

[](#installation)

You may install Naive Bayes into your project using the Composer package manager:

```
composer require assisted-mindfulness/naive-bayes
```

Learning
--------

[](#learning)

Before the algorithm can do anything, it requires a training set with historical information. To teach your classifier which category the text belongs to, call the `learn` method:

```
$classifier = new Classifier();

$classifier
    ->learn('I love sunny days', 'positive')
    ->learn('I hate rain', 'negative');
```

Guessing
--------

[](#guessing)

After you have trained the classifier, you can use the prediction of which category the transmitted text belongs to, for example:

```
$classifier->most('is a sunny days'); // positive
$classifier->most('there will be rain'); // negative
```

In order for you to enter more similar information, you can use:

```
$classifier->guess('is a sunny days');

/*
items: array:2 [
  "positive" => 0.0064
  "negative" => 0.0039062
]
*/
```

Uneven
------

[](#uneven)

When the training set contains unbalanced data not intentionally but due to insufficient data, you can enable an 'uneven' mode that equalizes the probability calculation for document types.

```
$classifier
   ->uneven()
   ->guess('is a sunny days');
```

Tokenizer
---------

[](#tokenizer)

The algorithm utilizes a tokenizer to segment the text into words. By default, it splits the text by spaces and includes words with a length of more than 3 symbols. You can also define your custom tokenizer using the following example:

```
$classifier = new Classifier();

$classifier->setTokenizer(function (string $string) {
    return Str::of($string)
        ->lower()
        ->matchAll('/[[:alpha:]]+/u')
        ->filter(fn (string $word) => Str::length($word) > 3);
});
```

Wrapping up
-----------

[](#wrapping-up)

There you have it! Even with a **very** small training set the algorithm can still return some decent results. For example, [Naive Bayes has been proven to give decent results in sentiment analyses](http://www-nlp.stanford.edu/courses/cs224n/2009/fp/3.pdf).

Moreover, Naive Bayes can be applied to more than just text. If you have other ways of calculating the probabilities of your metrics you can also plug those in and it will just as good.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance62

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 81.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~161 days

Recently: every ~125 days

Total

9

Last Release

239d ago

Major Versions

0.0.8 → 1.0.02025-09-21

PHP version history (2 changes)0.0.1PHP ^8.0

0.0.2PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c47797b11041f37c2eec74b09bc6619c8997467d690797ebad0e6ab7cb232b7?d=identicon)[tabuna](/maintainers/tabuna)

---

Top Contributors

[![tabuna](https://avatars.githubusercontent.com/u/5102591?v=4)](https://github.com/tabuna "tabuna (27 commits)")[![bdelespierre](https://avatars.githubusercontent.com/u/1086339?v=4)](https://github.com/bdelespierre "bdelespierre (3 commits)")[![TheDigitalOrchard](https://avatars.githubusercontent.com/u/3195423?v=4)](https://github.com/TheDigitalOrchard "TheDigitalOrchard (2 commits)")[![SadElephant](https://avatars.githubusercontent.com/u/7434276?v=4)](https://github.com/SadElephant "SadElephant (1 commits)")

---

Tags

classifiermachine-learning

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/assisted-mindfulness-naive-bayes/health.svg)

```
[![Health](https://phpackages.com/badges/assisted-mindfulness-naive-bayes/health.svg)](https://phpackages.com/packages/assisted-mindfulness-naive-bayes)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[illuminate/validation

The Illuminate Validation package.

18936.7M1.4k](/packages/illuminate-validation)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
