mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-11-29 00:06:31 +00:00
Fix apriori keys (#238)
* Add test to check keys of rules * Reindex after array_filter/array_unique in Apriori
This commit is contained in:
parent
8aed3b9286
commit
add00c6108
@ -212,9 +212,9 @@ class Apriori implements Associator
|
|||||||
*/
|
*/
|
||||||
private function frequent(array $samples): array
|
private function frequent(array $samples): array
|
||||||
{
|
{
|
||||||
return array_filter($samples, function ($entry) {
|
return array_values(array_filter($samples, function ($entry) {
|
||||||
return $this->support($entry) >= $this->support;
|
return $this->support($entry) >= $this->support;
|
||||||
});
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,7 +234,7 @@ class Apriori implements Associator
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$candidate = array_unique(array_merge($p, $q));
|
$candidate = array_values(array_unique(array_merge($p, $q)));
|
||||||
|
|
||||||
if ($this->contains($candidates, $candidate)) {
|
if ($this->contains($candidates, $candidate)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -101,6 +101,18 @@ class AprioriTest extends TestCase
|
|||||||
$this->assertEquals([['a']], $L[1]);
|
$this->assertEquals([['a']], $L[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAprioriL3(): void
|
||||||
|
{
|
||||||
|
$sample = [['a', 'b', 'c']];
|
||||||
|
|
||||||
|
$apriori = new Apriori(0, 0);
|
||||||
|
$apriori->train($sample, []);
|
||||||
|
|
||||||
|
$L = $apriori->apriori();
|
||||||
|
|
||||||
|
$this->assertEquals([['a', 'b', 'c']], $L[3]);
|
||||||
|
}
|
||||||
|
|
||||||
public function testGetRules(): void
|
public function testGetRules(): void
|
||||||
{
|
{
|
||||||
$apriori = new Apriori(0.4, 0.8);
|
$apriori = new Apriori(0.4, 0.8);
|
||||||
|
Loading…
Reference in New Issue
Block a user