承接 enzomc/php-fpgrowth 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

enzomc/php-fpgrowth

最新稳定版本:1.1

Composer 安装命令:

composer require enzomc/php-fpgrowth

包简介

PHP implementation of the Frequent Pattern Growth algorithm

README 文档

README

A PHP implementation of the Frequent Pattern Growth algorithm

Getting Started

You can install the package with composer:

composer require enzomc/php-fpgrowth

Usage

Run algorithm

use EnzoMC\PhpFPGrowth\FPGrowth;

$support = 3;
$confidence = 0.7;

$fpgrowth = new FPGrowth($support, $confidence);

$transactions = [
    ['M', 'O', 'N', 'K', 'E', 'Y'],
    ['D', 'O', 'N', 'K', 'E', 'Y'],
    ['M', 'A', 'K', 'E'],
    ['M', 'U', 'C', 'K', 'Y'],
    ['C', 'O', 'O', 'K', 'I', 'E']
];

$fpgrowth->run($transactions);

$patterns = $fpgrowth->getPatterns();
$rules = $fpgrowth->getRules();

Returned results

Patterns returns as array of arrays like:

[
    ['ITEM_1,ITEM_2' => 3],
    ['ITEM_3' => 5],
    ...
]

Where key is itemset, value is support of that itemset

Rules returns as array of arrays like:

[
    ['ITEM_1,ITEM_2', 'ITEM_3', 0.7],
    ['ITEM_4','ITEM_5', 0.7],
    ...
]

Where first value is left path of that rule, second value is right path of that rule and third value is confidence of that rule

Result with example transactions

var_dump($patterns);

array(10) {
  ["M"]=>
  int(3)
  ["K,M"]=>
  int(3)
  ["Y"]=>
  int(3)
  ["K,Y"]=>
  int(3)
  ["E,O"]=>
  int(4)
  ["E,K"]=>
  int(4)
  ["E,K,O"]=>
  int(4)
  ["O"]=>
  int(4)
  ["K,O"]=>
  int(4)
  ["K"]=>
  int(5)
}

var_dump($rules);

array(11) {
  [0]=>
  array(3) {
    [0]=>
    string(1) "M"
    [1]=>
    string(1) "K"
    [2]=>
    float(1)
  }
  [1]=>
  array(3) {
    [0]=>
    string(1) "Y"
    [1]=>
    string(1) "K"
    [2]=>
    float(1)
  }
  [2]=>
  array(3) {
    [0]=>
    string(1) "O"
    [1]=>
    string(1) "E"
    [2]=>
    float(1)
  }
  [3]=>
  array(3) {
    [0]=>
    string(1) "K"
    [1]=>
    string(1) "E"
    [2]=>
    float(0.8)
  }
  [4]=>
  array(3) {
    [0]=>
    string(1) "K"
    [1]=>
    string(3) "E,O"
    [2]=>
    float(0.8)
  }
  [5]=>
  array(3) {
    [0]=>
    string(1) "O"
    [1]=>
    string(3) "E,K"
    [2]=>
    float(1)
  }
  [6]=>
  array(3) {
    [0]=>
    string(3) "E,K"
    [1]=>
    string(1) "O"
    [2]=>
    float(1)
  }
  [7]=>
  array(3) {
    [0]=>
    string(3) "E,O"
    [1]=>
    string(1) "K"
    [2]=>
    float(1)
  }
  [8]=>
  array(3) {
    [0]=>
    string(3) "K,O"
    [1]=>
    string(1) "E"
    [2]=>
    float(1)
  }
  [9]=>
  array(3) {
    [0]=>
    string(1) "K"
    [1]=>
    string(1) "O"
    [2]=>
    float(0.8)
  }
  [10]=>
  array(3) {
    [0]=>
    string(1) "O"
    [1]=>
    string(1) "K"
    [2]=>
    float(1)
  }
}

统计信息

  • 总下载量: 2.7k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 0
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-06-17