use of com.alibaba.alink.params.dataproc.vector.VectorImputerTrainParams.Strategy in project Alink by alibaba.
the class VectorImputerModelDataConverter method serializeModel.
/**
* Serialize the model data to "Tuple3<Params, List<String>, List<Row>>".
*
* @param modelData The model data to serialize.
* @return The serialization result.
*/
public Tuple3<Params, Iterable<String>, Iterable<Row>> serializeModel(Tuple3<Strategy, BaseVectorSummary, Double> modelData) {
Strategy strategy = modelData.f0;
BaseVectorSummary summary = modelData.f1;
double fillValue = modelData.f2;
double[] values = null;
Params meta = new Params().set(SELECTED_COL, vectorColName).set(STRATEGY, strategy);
switch(strategy) {
case MIN:
if (summary.min() instanceof DenseVector) {
values = ((DenseVector) summary.min()).getData();
} else {
values = ((SparseVector) summary.min()).toDenseVector().getData();
}
break;
case MAX:
if (summary.max() instanceof DenseVector) {
values = ((DenseVector) summary.max()).getData();
} else {
values = ((SparseVector) summary.max()).toDenseVector().getData();
}
break;
case MEAN:
if (summary.mean() instanceof DenseVector) {
values = ((DenseVector) summary.mean()).getData();
} else {
values = ((SparseVector) summary.mean()).getValues();
}
break;
default:
meta.set(FILL_VALUE, fillValue);
}
List<String> data = new ArrayList<>();
data.add(JsonConverter.toJson(values));
return Tuple3.of(meta, data, new ArrayList<>());
}
use of com.alibaba.alink.params.dataproc.vector.VectorImputerTrainParams.Strategy in project Alink by alibaba.
the class VectorImputerModelDataConverter method deserializeModel.
/**
* Deserialize the model data.
*
* @param meta The model meta data.
* @param data The model concrete data.
* @param additionData The additional data.
* @return The model data used by mapper.
*/
@Override
public Tuple3<Strategy, double[], Double> deserializeModel(Params meta, Iterable<String> data, Iterable<Row> additionData) {
Strategy strategy = meta.get(STRATEGY);
double[] values = null;
if (data.iterator().hasNext()) {
values = JsonConverter.fromJson(data.iterator().next(), double[].class);
}
Double fillValue = meta.get(FILL_VALUE);
return Tuple3.of(strategy, values, fillValue);
}
Aggregations