Example #1
0
  private static ProbabilityDistribution getPriorProbabilities(Target target) {
    ProbabilityDistribution result = new ProbabilityDistribution();

    List<TargetValue> values = target.getTargetValues();
    for (TargetValue value : values) {

      // "The defaultValue attribute is used only if the optype of the field is continuous"
      if (value.getDefaultValue() != null) {
        throw new InvalidFeatureException(value);
      }

      String targetCategory = value.getValue();
      Double probability = value.getPriorProbability();

      if (targetCategory == null || probability == null) {
        continue;
      }

      result.put(targetCategory, probability);
    }

    if (result.isEmpty()) {
      return null;
    }

    return result;
  }
Example #2
0
  private static Double getDefaultValue(Target target) {
    List<TargetValue> values = target.getTargetValues();

    if (values.isEmpty()) {
      return null;
    } // End if

    if (values.size() != 1) {
      throw new InvalidFeatureException(target);
    }

    TargetValue value = values.get(0);

    // "The value and priorProbability attributes are used only if the optype of the field is
    // categorical or ordinal"
    if (value.getValue() != null || value.getPriorProbability() != null) {
      throw new InvalidFeatureException(value);
    }

    return value.getDefaultValue();
  }