https://github.com/krypt0nn/cati-tree
Category Identification Tree
https://github.com/krypt0nn/cati-tree
machine-learning php
Last synced: 12 days ago
JSON representation
Category Identification Tree
- Host: GitHub
- URL: https://github.com/krypt0nn/cati-tree
- Owner: krypt0nn
- License: gpl-3.0
- Created: 2021-05-23T18:08:20.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-06-01T12:54:56.000Z (about 5 years ago)
- Last Synced: 2026-05-17T09:50:59.341Z (about 2 months ago)
- Topics: machine-learning, php
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🚀 CATI Tree
**CATI Tree** *(Category Identification Tree)* - library for realization datasets identification in PHP 7.4+
This data structure and the algorithm implemented in it were invented by me so they certainly will work like pieces of shit. More useful information (in Russian) you can read [here](https://twitter.com/krypt0nn/status/1394701165238046724?s=20)
## Installation
```
composer require krypt0nn/cati-tree
```
## Example of work
### Tree
```php
$tree = CATI\Tree::train ([
'a' => [
[1, 2, 3],
[1, 2, 4],
[5, 6, 7],
[6, 7, 8],
[2, 3, 6]
],
'b' => [
[2, 3, 1]
]
]);
echo 'Training accuracy: '. $tree->acuracy();
file_put_contents ('tree.json', json_encode ($tree->export ()));
```
```php
$tree = CATI\Tree::load (json_decode (file_get_contents ('tree.json'), true));
echo $tree->predict ([6, 7, 8]) ?: 'unknown'; // a
```
### Random forest
```php
$forest = CATI\RandomForest::create ([
'a' => [
[1, 2, 3],
[1, 2, 4],
[5, 6, 7],
[6, 7, 8],
[2, 3, 6]
],
'b' => [
[2, 3, 1]
]
], forestSize: 5);
echo 'Training accuracy: '. $forest->acuracy();
file_put_contents ('forest.json', json_encode ($forest->export ()));
```
```php
$forest = CATI\RandomForest::load (json_decode (file_get_contents ('forest.json'), true));
print_r ($forest->probability ([6, 7, 8]));
```
Author: [Nikita Podvirnyy](https://vk.com/technomindlp)