Search in sources :

Example 1 with UndefinedLabelException

use of org.apache.ignite.ml.math.exceptions.preprocessing.UndefinedLabelException in project ignite by apache.

the class EncoderTrainer method updateLabelFrequenciesForNextRow.

/**
 * Updates frequencies by values and features.
 *
 * @param row Feature vector.
 * @param labelFrequencies Holds the frequencies of categories by values and features.
 * @return Updated frequencies by values and features.
 */
private Map<String, Integer> updateLabelFrequenciesForNextRow(LabeledVector row, Map<String, Integer> labelFrequencies) {
    if (labelFrequencies == null)
        labelFrequencies = new HashMap<>();
    String strVal;
    Object lbVal = row.label();
    if (lbVal.equals(Double.NaN) || lbVal == null)
        throw new UndefinedLabelException(row);
    else if (lbVal instanceof String)
        strVal = (String) lbVal;
    else if (lbVal instanceof Double)
        strVal = String.valueOf(lbVal);
    else
        throw new RuntimeException("The type " + lbVal.getClass() + " is not supported for the feature values.");
    if (labelFrequencies.containsKey(strVal))
        labelFrequencies.put(strVal, (labelFrequencies.get(strVal)) + 1);
    else
        labelFrequencies.put(strVal, 1);
    return labelFrequencies;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) UndefinedLabelException(org.apache.ignite.ml.math.exceptions.preprocessing.UndefinedLabelException)

Aggregations

HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 UndefinedLabelException (org.apache.ignite.ml.math.exceptions.preprocessing.UndefinedLabelException)1