を使用しています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
それは感謝しました! –