分類レポート
メインの分類器のメトリックを計算するためのクラス: 精度、再現率、F1スコア および サポート。
レポート
レポートを生成するには、以下のパラメータを提供する必要があります:
- $actualLabels - (array) 真の標本ラベル
- $predictedLabels - (array) 予測ラベル (例えば、テストグループから)
use Phpml\Metric\ClassificationReport;
$actualLabels = ['cat', 'ant', 'bird', 'bird', 'bird'];
$predictedLabels = ['cat', 'cat', 'bird', 'bird', 'ant'];
$report = new ClassificationReport($actualLabels, $predictedLabels);
マトリックス
レポートを作成した後で、その個々のメトリックを描画することができます:
- 精度 (
getPrecision()
) - 関連のある取り出されたインスタンスの断片 - 再現率 (
getRecall()
) - 取り出された関連のあるインスタンスの断片 - F1 スコア (
getF1score()
) - テストの精度の評価 - サポート (
getSupport()
) - 標本のテストの数
$precision = $report->getPrecision();
// $precision = ['cat' => 0.5, 'ant' => 0.0, 'bird' => 1.0];
例
use Phpml\Metric\ClassificationReport;
$actualLabels = ['cat', 'ant', 'bird', 'bird', 'bird'];
$predictedLabels = ['cat', 'cat', 'bird', 'bird', 'ant'];
$report = new ClassificationReport($actualLabels, $predictedLabels);
$report->getPrecision();
// ['cat' => 0.5, 'ant' => 0.0, 'bird' => 1.0]
$report->getRecall();
// ['cat' => 1.0, 'ant' => 0.0, 'bird' => 0.67]
$report->getF1score();
// ['cat' => 0.67, 'ant' => 0.0, 'bird' => 0.80]
$report->getSupport();
// ['cat' => 1, 'ant' => 1, 'bird' => 3]
$report->getAverage();
// ['precision' => 0.75, 'recall' => 0.83, 'f1score' => 0.73]