PHPackages                             ifaqih/ifnaivebayes - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. ifaqih/ifnaivebayes

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ifaqih/ifnaivebayes
===================

Naive Bayes library for PHP

1.0.0(3y ago)0161MITPHPPHP &gt;= 8.0

Since Feb 4Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ifaqih/IFNaiveBayes)[ Packagist](https://packagist.org/packages/ifaqih/ifnaivebayes)[ RSS](/packages/ifaqih-ifnaivebayes/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (1)DependenciesVersions (2)Used By (1)

Naive Bayes Classifier
======================

[](#naive-bayes-classifier)

Naive Bayes classifier (NBC) is a machine learning method that utilizes probability and statistical calculations proposed by British scientist Thomas Bayes, which predicts future probabilities based on past experience.

PHP Version: 8.0 or aboveInstallation
------------

[](#installation)

### With Composer:

[](#with-composer)

```
composer require ifaqih/ifnaivebayes
```

Use The Library
---------------

[](#use-the-library)

```
use IFaqih\AIMethods\NaiveBayes;
```

Set Data Method
---------------

[](#set-data-method)

Method to set the data to be processed.

```
class::set_data()
```

- Type: static
- Parameter data type: `array $data`
- Return data type: `void`

### Prototype:

[](#prototype)

```
$data = [
    "attribute name"   =>  value,
    "attribute name"   =>  value,
    "attribute name"   =>  value
]
```

info:

- label: something that represents the group name
- attribute: parameters to be calculated in the classification process

Set Training Data Method
------------------------

[](#set-training-data-method)

A method for organizing past classification data that will be used as the basis for future classifications.

```
class::set_training_data()
```

- Type: static
- Parameter data type: `array|object $data, int $type_training_data = 0, ?string $key_label = null`
- Return data type: `void`

### Prototype 1:

[](#prototype-1)

```
$data = [
    [
        "attribute name"   =>  value,
        "attribute name"   =>  value,
        "attribute name"   =>  value,
        "label"            =>  value
    ]
];

$type_training_data = 0;
or
$type_training_data = NB_BY_ROWS;
```

### Prototype 2:

[](#prototype-2)

```
$data = [
    "label" =>  [
        [
            "attribute name"   =>  value,
            "attribute name"   =>  value,
            "attribute name"   =>  value
        ]
    ]
];

$type_training_data = 1;
or
$type_training_data = NB_BY_GROUP_LABEL;
```

### Prototype 3:

[](#prototype-3)

Set training data based on number of attributes and number of labels. If using this prototype does not require data input (in the set\_data() method) and will skip the attribute calculation stage, because it is assumed to have performed attribute calculations manually.

```
$data = [
    "label" =>  [
        "attributes"    =>  [
            "attribute name"   =>  number of attributes on the label,
            "attribute name"   =>  number of attributes on the label,
            "attribute name"   =>  number of attributes on the label
        ],
        "total"         =>  number of labels
    ]
];

$type_training_data = 1;
or
$type_training_data = NB_BY_NUMBER;
```

info:

- label: something that represents the group name
- attribute name: parameters to be calculated in the classification process
- "$key\_label" parameter is not needed when using the second prototype

Process Method
--------------

[](#process-method)

The method that will perform the classification calculation.

```
class::process()
```

- Type: static
- Parameter data type: `?array $data = null, array|object|null $training_data = null, int $type_training_data = 0, ?string $key_label = null, bool $boolean_returned = true, bool $clear_after = false`
- Return data type: `string|bool|null`

info: do not include parameters if already set data using 'set' method, otherwise this parameter data will overwrite data which have been set using 'set' method

Get Result Method
-----------------

[](#get-result-method)

Method to get the result of the classification process.

```
class::get_result()
```

- Type: static
- Parameter data type: not needed
- Return data type: `string|int|float|null`

Get Result Point Method
-----------------------

[](#get-result-point-method)

Method to get the points result from the classification process.

```
class::get_result_point()
```

- Type: static
- Parameter data type: `?string $label = null`
- Return data type: `object|float|int|null`

info: parameter in this method is used to get the calculation result points which refers to the requested label and will be returned in float data type, if parameter is not filled or contains null it will return all calculation result points in object data type

Clear Method
------------

[](#clear-method)

This method will delete all data stored statically on the class.

```
class::clear()
```

- Type: static
- Parameter data type: not needed
- Return data type: `void`

Test Results
------------

[](#test-results)

Number of training data = 100000

```
Example Prototype Training Data 1:

array(5) {
  ["result"]=>
  string(2) "TI"
  ["point"]=>
  object(stdClass)(3) {
    ["TI"]=>
    float(0.0020101198329071602)
    ["TM"]=>
    float(0.00048783922881731547)
    ["TP"]=>
    float(0.0011221592061979964)
  }
  ["start_at"]=>
  float(1666072755.080761)
  ["end_at"]=>
  float(1666072755.145308)
  ["execution_time"]=>
  float(0.06454706192016602)
}

Example Prototype Training Data 2:

array(5) {
  ["result"]=>
  string(2) "TI"
  ["point"]=>
  object(stdClass)(3) {
    ["TI"]=>
    float(0.0020101198329071602)
    ["TM"]=>
    float(0.00048783922881731547)
    ["TP"]=>
    float(0.0011221592061979964)
  }
  ["start_at"]=>
  float(1666072755.27086)
  ["end_at"]=>
  float(1666072755.291312)
  ["execution_time"]=>
  float(0.020452022552490234)
}

Example Prototype Training Data 3:

array(5) {
  ["result"]=>
  string(2) "TI"
  ["point"]=>
  object(stdClass)(3) {
    ["TI"]=>
    float(0.0020101198329071602)
    ["TM"]=>
    float(0.00048783922881731547)
    ["TP"]=>
    float(0.0011221592061979964)
  }
  ["start_at"]=>
  float(1666072755.291341)
  ["end_at"]=>
  float(1666072755.29135)
  ["execution_time"]=>
  float(8.821487426757812E-6)
}
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1246d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/43080806?v=4)[Ikhwanul Faqih](/maintainers/ifaqih)[@ifaqih](https://github.com/ifaqih)

---

Top Contributors

[![ifaqih](https://avatars.githubusercontent.com/u/43080806?v=4)](https://github.com/ifaqih "ifaqih (31 commits)")

---

Tags

artificial-intelligence-algorithmsmachine-learningnaive-bayesnaive-bayes-classifier

### Embed Badge

![Health badge](/badges/ifaqih-ifnaivebayes/health.svg)

```
[![Health](https://phpackages.com/badges/ifaqih-ifnaivebayes/health.svg)](https://phpackages.com/packages/ifaqih-ifnaivebayes)
```

###  Alternatives

[ezsystems/ezplatform-standard-design

eZ Platform Standard Design Bundle

30714.0k10](/packages/ezsystems-ezplatform-standard-design)[kunstmaan/generator-bundle

If you're like us, you like to build applications without having to do the same things over and over again and dislike copy/pasting code and change a couple of words every time you need feature X. The KunstmaanGeneratorBundle gives you the possibility to generate code for new bundles, adminlists and can even make you a basic default website. That way you don't have to wait too long before you see some results and you have more time to do other things. Easy no?

23115.3k2](/packages/kunstmaan-generator-bundle)

PHPackages © 2026

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