use of org.apache.ignite.ml.math.exceptions.preprocessing.IllegalFeatureTypeException in project ignite by apache.
the class StringEncoderPreprocessor method apply.
/**
* Applies this preprocessor.
*
* @param k Key.
* @param v Value.
* @return Preprocessed row.
*/
@Override
public LabeledVector apply(K k, V v) {
LabeledVector tmp = basePreprocessor.apply(k, v);
double[] res = new double[tmp.size()];
for (int i = 0; i < res.length; i++) {
Object tmpObj = tmp.getRaw(i);
if (handledIndices.contains(i)) {
if (tmpObj.equals(Double.NaN) && encodingValues[i].containsKey(KEY_FOR_NULL_VALUES))
res[i] = encodingValues[i].get(KEY_FOR_NULL_VALUES);
else if (encodingValues[i].containsKey(tmpObj))
res[i] = encodingValues[i].get(tmpObj);
else
throw new UnknownCategorialValueException(tmpObj.toString());
} else {
if (tmpObj instanceof Number)
res[i] = (double) tmpObj;
else
throw new IllegalFeatureTypeException(tmpObj.getClass(), tmpObj, Double.class);
}
}
return new LabeledVector(VectorUtils.of(res), tmp.label());
}
Aggregations