0

我正在使用 Ian Barbers Naive Bayes 分析类来分析学校项目的句子情绪。我已经创建了自己的正面中性和负面数据集。我的问题是我不知道如何实现中性并让班级找到它们。下面的链接是我正在使用的 php 类

http://phpir.com/bayesian-opinion-mining

4

1 回答 1

2

好吧,该Opinion课程已经非常灵活地添加了新的“情感课程”。只是该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
于 2011-12-30T06:45:42.050 回答