metric = new MCC(); } /** * @test */ public function build() : void { $this->assertInstanceOf(MCC::class, $this->metric); $this->assertInstanceOf(Metric::class, $this->metric); } /** * @test */ public function range() : void { $tuple = $this->metric->range(); $this->assertInstanceOf(Tuple::class, $tuple); $this->assertCount(2, $tuple); $this->assertGreaterThan($tuple[0], $tuple[1]); } /** * @test */ public function compatibility() : void { $expected = [ EstimatorType::classifier(), EstimatorType::anomalyDetector(), ]; $this->assertEquals($expected, $this->metric->compatibility()); } /** * @test * @dataProvider scoreProvider * * @param (string|int)[] $predictions * @param (string|int)[] $labels * @param float $expected */ public function score(array $predictions, array $labels, float $expected) : void { [$min, $max] = $this->metric->range()->list(); $score = $this->metric->score($predictions, $labels); $this->assertThat( $score, $this->logicalAnd( $this->greaterThanOrEqual($min), $this->lessThanOrEqual($max) ) ); $this->assertEquals($expected, $score); } /** * @return Generator */ public function scoreProvider() : Generator { yield [ ['wolf', 'lamb', 'wolf', 'lamb', 'wolf'], ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], 0.16666666666666666, ]; yield [ ['wolf', 'wolf', 'lamb', 'lamb', 'lamb'], ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], -1.0, ]; yield [ ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], ['lamb', 'lamb', 'wolf', 'wolf', 'wolf'], 1.0, ]; yield [ [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], 0.6123724356957946, ]; yield [ [0, 0, 0, 1, 0], [0, 0, 0, 1, 0], 1.0, ]; yield [ [1, 1, 1, 0, 1], [0, 0, 0, 1, 0], -1.0, ]; } }