예제 #1
0
  @Override
  public void updateNode(Instance inst) throws Exception {
    super.updateDistribution(inst);

    for (int i = 0; i < inst.numAttributes(); i++) {
      Attribute a = inst.attribute(i);
      if (i != inst.classIndex()) {
        ConditionalSufficientStats stats = m_nodeStats.get(a.name());
        if (stats == null) {
          if (a.isNumeric()) {
            stats = new GaussianConditionalSufficientStats();
          } else {
            stats = new NominalConditionalSufficientStats();
          }
          m_nodeStats.put(a.name(), stats);
        }

        stats.update(
            inst.value(a), inst.classAttribute().value((int) inst.classValue()), inst.weight());
      }
    }
  }
예제 #2
0
  /**
   * Returns a list of split candidates
   *
   * @param splitMetric the splitting metric to use
   * @return a list of split candidates
   */
  public List<SplitCandidate> getPossibleSplits(SplitMetric splitMetric) {

    List<SplitCandidate> splits = new ArrayList<SplitCandidate>();

    // null split
    List<Map<String, WeightMass>> nullDist = new ArrayList<Map<String, WeightMass>>();
    nullDist.add(m_classDistribution);
    SplitCandidate nullSplit =
        new SplitCandidate(
            null, nullDist, splitMetric.evaluateSplit(m_classDistribution, nullDist));
    splits.add(nullSplit);

    for (Map.Entry<String, ConditionalSufficientStats> e : m_nodeStats.entrySet()) {
      ConditionalSufficientStats stat = e.getValue();

      SplitCandidate splitCandidate = stat.bestSplit(splitMetric, m_classDistribution, e.getKey());

      if (splitCandidate != null) {
        splits.add(splitCandidate);
      }
    }

    return splits;
  }