krypt0nn / cati-tree
分类识别树
0.2.3
2021-06-01 12:54 UTC
Requires
- php: >=7.4
README
CATI Tree (分类识别树) - PHP 7.4+ 实现数据集识别的库
这个数据结构和其中实现的算法是我发明的,所以它们肯定像狗屎一样工作。更多有用信息(俄语)请阅读这里
安装
composer require krypt0nn/cati-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
随机森林
$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]));