ankane/rcf

PHP的随机切割森林异常检测

v0.1.2 2023-02-11 18:55 UTC

This package is not auto-updated.

Last update: 2024-09-22 02:36:58 UTC


README

随机切割森林 (RCF) 的 PHP 异常检测

Build Status

安装

运行

composer require ankane/rcf

将脚本添加到 composer.json 以下载共享库

    "scripts": {
        "post-install-cmd": "Rcf\\Vendor::check",
        "post-update-cmd": "Rcf\\Vendor::check"
    }

然后运行

composer install

入门指南

创建具有3个维度的森林

$forest = new Rcf\Forest(3);

评分一个点

$forest->score([1.0, 2.0, 3.0]);

使用一个点更新

$forest->update([1.0, 2.0, 3.0]);

示例

$forest = new Rcf\Forest(3);

for ($i = 0; $i < 200; $i++) {
    $point = [];
    $point[0] = mt_rand() / mt_getrandmax();
    $point[1] = mt_rand() / mt_getrandmax();
    $point[2] = mt_rand() / mt_getrandmax();

    // make the second to last point an anomaly
    if ($i == 198) {
        $point[1] = 2;
    }

    $score = $forest->score($point);
    echo "point = $i, score = $score\n";
    $forest->update($point);
}

参数

设置参数

new Rcf\Forest(
    $dimensions,
    shingleSize: 1,         // shingle size to use
    sampleSize: 256,        // points to keep in sample for each tree
    numberOfTrees: 100,     // number of trees to use in the forest
    randomSeed: 42,         // random seed to use
    parallel: false         // enable parallel execution
)

参考文献

历史记录

查看变更日志

贡献

鼓励每个人帮助改进此项目。以下是一些你可以提供帮助的方式

开始开发

git clone https://github.com/ankane/random-cut-forest-php.git
cd random-cut-forest-php
composer install
composer test