krypt0nn/cati-tree

Category Identification Tree

0.2.3 2021-06-01 12:54 UTC

This package is auto-updated.

Last update: 2024-04-29 05:05:27 UTC


README

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

Installation

composer require krypt0nn/cati-tree

Example of work

Tree

$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 ()));
$tree = CATI\Tree::load (json_decode (file_get_contents ('tree.json'), true));

echo $tree->predict ([6, 7, 8]) ?: 'unknown'; // a

Random forest

$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 ()));
$forest = CATI\RandomForest::load (json_decode (file_get_contents ('forest.json'), true));

print_r ($forest->probability ([6, 7, 8]));

Author: Nikita Podvirnyy