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();
}
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();
}
Aggregations