을 사용하고있는 PHP 클래스입니다. classify
메서드는 "이전"정적 계산을 구현했습니다. 그러나 쉽게 대체 할 수 있습니다 foreach
:
private $classes = array('pos', 'neg', 'neutr');
private $classTokCounts = array('pos' => 0, 'neg' => 0, 'neutr' => 0);
private $classDocCounts = array('pos' => 0, 'neg' => 0, 'neutr' => 0);
private $prior = array('pos' => 1.0/3.0, 'neg' => 1.0/3.0, 'neutr' => 1.0/3.0);
public function classify($document) {
// remove those:
//$this->prior['pos'] = $this->classDocCounts['pos']/$this->docCount;
//$this->prior['neg'] = $this->classDocCounts['neg']/$this->docCount;
// add this:
foreach($this->classes as $class) {
$this->prior[$class] = $this->classDocCounts[$class]/$this->docCount;
}
// the rest is fine
그 덕분에! –