Skip to content

Commit de4d302

Browse files
committed
Don't overwrite log priors
1 parent f3e0d92 commit de4d302

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

src/Classifiers/NaiveBayes.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public function partial(Dataset $dataset) : void
254254
}
255255
}
256256

257-
$total = array_sum($columnCounts) + (count($columnCounts) * $this->smoothing);
257+
$total = array_sum($columnCounts) + $this->smoothing * count($columnCounts);
258258

259259
$probs = [];
260260

@@ -275,8 +275,6 @@ public function partial(Dataset $dataset) : void
275275
if ($this->fitPriors) {
276276
$total = array_sum($this->classCounts);
277277

278-
$this->logPriors = [];
279-
280278
foreach ($this->classCounts as $class => $weight) {
281279
$this->logPriors[$class] = log($weight / $total);
282280
}

0 commit comments

Comments
 (0)