Search in sources :

Example 1 with IllegalFeatureTypeException

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());
}
Also used : UnknownCategorialValueException(org.apache.ignite.ml.math.exceptions.preprocessing.UnknownCategorialValueException) LabeledVector(org.apache.ignite.ml.structures.LabeledVector) DeployableObject(org.apache.ignite.ml.environment.deploy.DeployableObject) IllegalFeatureTypeException(org.apache.ignite.ml.math.exceptions.preprocessing.IllegalFeatureTypeException)

Aggregations

DeployableObject (org.apache.ignite.ml.environment.deploy.DeployableObject)1 IllegalFeatureTypeException (org.apache.ignite.ml.math.exceptions.preprocessing.IllegalFeatureTypeException)1 UnknownCategorialValueException (org.apache.ignite.ml.math.exceptions.preprocessing.UnknownCategorialValueException)1 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)1