1

Weka 中使用的概率的平均值是多少?里面的代码在distributionForInstanceAverage做什么?

4

1 回答 1

1

它只是返回每个基本分类器的概率分布的平均值(在 Vote 中学习或在外部构建并由 Vote 加载)。

它首先对在 Vote 中学习的任何模型求和,然后将任何加载的模型相加,然后按元素将数组除以模型的总数。

protected double[] distributionForInstanceAverage(Instance instance) throws Exception {

    //Init probs array with first classifier used within model (learnt or loaded)
    double[] probs = (m_Classifiers.length > 0) 
    ? getClassifier(0).distributionForInstance(instance)
        : m_preBuiltClassifiers.get(0).distributionForInstance(instance);

    //Add the distributions of any classifiers built within the Vote classifier to probs array
    for (int i = 1; i < m_Classifiers.length; i++) {
      double[] dist = getClassifier(i).distributionForInstance(instance);
      for (int j = 0; j < dist.length; j++) {
          probs[j] += dist[j];
      }
    }

    //Add the distributions of any classifiers built outside of the Vote classifier (loaded in) to the probs array
    int index = (m_Classifiers.length > 0) ? 0 : 1;
    for (int i = index; i < m_preBuiltClassifiers.size(); i++) {
      double[] dist = m_preBuiltClassifiers.get(i).distributionForInstance(instance);
      for (int j = 0; j < dist.length; j++) {
        probs[j] += dist[j];
      }
    }

    //Divide each probability by the total number of classifiers used in Vote (to get the mean)
    for (int j = 0; j < probs.length; j++) {
      probs[j] /= (double)(m_Classifiers.length + m_preBuiltClassifiers.size());
    }
    return probs;
  }
于 2012-12-30T15:05:27.183 回答