Search in sources :

Example 1 with MaxAbsScaler

use of com.alibaba.alink.pipeline.dataproc.MaxAbsScaler in project Alink by alibaba.

the class Chap07 method c_3_3.

static void c_3_3() throws Exception {
    CsvSourceBatchOp source = new CsvSourceBatchOp().setFilePath(DATA_DIR + ORIGIN_FILE).setSchemaStr(SCHEMA_STRING);
    source.lazyPrintStatistics("< Origin data >");
    MaxAbsScaler scaler = new MaxAbsScaler().setSelectedCols(FEATURE_COL_NAMES);
    scaler.fit(source).transform(source).lazyPrintStatistics("< after MaxAbs Scale >");
    BatchOperator.execute();
}
Also used : MaxAbsScaler(com.alibaba.alink.pipeline.dataproc.MaxAbsScaler) VectorMaxAbsScaler(com.alibaba.alink.pipeline.dataproc.vector.VectorMaxAbsScaler) CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)

Example 2 with MaxAbsScaler

use of com.alibaba.alink.pipeline.dataproc.MaxAbsScaler in project Alink by alibaba.

the class MaxAbsTest method test.

@Test
public void test() throws Exception {
    BatchOperator batchData = new TableSourceBatchOp(GenerateData.getBatchTable());
    StreamOperator streamData = new TableSourceStreamOp(GenerateData.getStreamTable());
    MaxAbsScalerModel model = new MaxAbsScaler().setSelectedCols("f0", "f1").setOutputCols("f0_1", "f1_1").fit(batchData);
    model.transform(batchData).lazyCollect();
    model.transform(streamData).print();
    MaxAbsScalerTrainBatchOp op = new MaxAbsScalerTrainBatchOp().setSelectedCols("f0", "f1").linkFrom(batchData);
    List<Row> rows = new MaxAbsScalerPredictBatchOp().linkFrom(op, batchData).collect();
    rows.sort(StandardScalerTest.compare);
    assertEquals(rows.get(0), Row.of(null, null));
    StandardScalerTest.assertRow(rows.get(1), Row.of(-0.25, -1.));
    StandardScalerTest.assertRow(rows.get(2), Row.of(0.25, 0.666));
    StandardScalerTest.assertRow(rows.get(3), Row.of(1.0, 0.6666));
    new MaxAbsScalerPredictStreamOp(op).linkFrom(streamData).print();
    StreamOperator.execute();
}
Also used : MaxAbsScaler(com.alibaba.alink.pipeline.dataproc.MaxAbsScaler) MaxAbsScalerPredictStreamOp(com.alibaba.alink.operator.stream.dataproc.MaxAbsScalerPredictStreamOp) MaxAbsScalerModel(com.alibaba.alink.pipeline.dataproc.MaxAbsScalerModel) TableSourceStreamOp(com.alibaba.alink.operator.stream.source.TableSourceStreamOp) Row(org.apache.flink.types.Row) TableSourceBatchOp(com.alibaba.alink.operator.batch.source.TableSourceBatchOp) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) Test(org.junit.Test)

Aggregations

MaxAbsScaler (com.alibaba.alink.pipeline.dataproc.MaxAbsScaler)2 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)1 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)1 TableSourceBatchOp (com.alibaba.alink.operator.batch.source.TableSourceBatchOp)1 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)1 MaxAbsScalerPredictStreamOp (com.alibaba.alink.operator.stream.dataproc.MaxAbsScalerPredictStreamOp)1 TableSourceStreamOp (com.alibaba.alink.operator.stream.source.TableSourceStreamOp)1 MaxAbsScalerModel (com.alibaba.alink.pipeline.dataproc.MaxAbsScalerModel)1 VectorMaxAbsScaler (com.alibaba.alink.pipeline.dataproc.vector.VectorMaxAbsScaler)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1