Search in sources :

Example 1 with VectorPolynomialExpand

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

the class VectorPolynomialExpandTest method test.

@Test
public void test() throws Exception {
    Row[] rows = new Row[] { Row.of("3.0, 4.0") };
    BatchOperator batchData = new MemSourceBatchOp(rows, new String[] { "vec" });
    StreamOperator streamData = new MemSourceStreamOp(rows, new String[] { "vec" });
    new VectorPolynomialExpandBatchOp().setDegree(2).setOutputCol("outv").setSelectedCol("vec").linkFrom(batchData);
    new VectorPolynomialExpandStreamOp().setDegree(2).setOutputCol("outv").setSelectedCol("vec").linkFrom(streamData);
    VectorPolynomialExpand pipeline = new VectorPolynomialExpand().setDegree(2).setOutputCol("outv").setSelectedCol("vec");
    pipeline.transform(batchData).collect();
    pipeline.transform(streamData).print();
    StreamOperator.execute();
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) MemSourceStreamOp(com.alibaba.alink.operator.stream.source.MemSourceStreamOp) VectorPolynomialExpand(com.alibaba.alink.pipeline.dataproc.vector.VectorPolynomialExpand) VectorPolynomialExpandStreamOp(com.alibaba.alink.operator.stream.dataproc.vector.VectorPolynomialExpandStreamOp) Row(org.apache.flink.types.Row) StreamOperator(com.alibaba.alink.operator.stream.StreamOperator) BatchOperator(com.alibaba.alink.operator.batch.BatchOperator) Test(org.junit.Test)

Example 2 with VectorPolynomialExpand

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

the class Chap08 method c_8.

static void c_8() throws Exception {
    BatchOperator<?> train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    BatchOperator<?> test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    PipelineModel featureExpand = new Pipeline().add(new VectorAssembler().setSelectedCols(FEATURE_COL_NAMES).setOutputCol(VEC_COL_NAME + "_0")).add(new VectorPolynomialExpand().setSelectedCol(VEC_COL_NAME + "_0").setOutputCol(VEC_COL_NAME).setDegree(2)).fit(train_data);
    train_data = featureExpand.transform(train_data);
    test_data = featureExpand.transform(test_data);
    train_data.lazyPrint(1);
    new LinearSvm().setVectorCol(VEC_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).fit(train_data).transform(test_data).link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("1").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics("LinearSVM"));
    new LogisticRegression().setVectorCol(VEC_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).fit(train_data).transform(test_data).link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("1").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics("LogisticRegression"));
    new LogisticRegression().setOptimMethod(OptimMethod.Newton).setVectorCol(VEC_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).fit(train_data).transform(test_data).link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("1").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics("LogisticRegression + OptimMethod.Newton"));
    BatchOperator.execute();
}
Also used : VectorPolynomialExpand(com.alibaba.alink.pipeline.dataproc.vector.VectorPolynomialExpand) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) VectorAssembler(com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler) LinearSvm(com.alibaba.alink.pipeline.classification.LinearSvm) LogisticRegression(com.alibaba.alink.pipeline.classification.LogisticRegression) PipelineModel(com.alibaba.alink.pipeline.PipelineModel) Pipeline(com.alibaba.alink.pipeline.Pipeline) EvalBinaryClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalBinaryClassBatchOp)

Aggregations

VectorPolynomialExpand (com.alibaba.alink.pipeline.dataproc.vector.VectorPolynomialExpand)2 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)1 EvalBinaryClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalBinaryClassBatchOp)1 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)1 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)1 StreamOperator (com.alibaba.alink.operator.stream.StreamOperator)1 VectorPolynomialExpandStreamOp (com.alibaba.alink.operator.stream.dataproc.vector.VectorPolynomialExpandStreamOp)1 MemSourceStreamOp (com.alibaba.alink.operator.stream.source.MemSourceStreamOp)1 Pipeline (com.alibaba.alink.pipeline.Pipeline)1 PipelineModel (com.alibaba.alink.pipeline.PipelineModel)1 LinearSvm (com.alibaba.alink.pipeline.classification.LinearSvm)1 LogisticRegression (com.alibaba.alink.pipeline.classification.LogisticRegression)1 VectorAssembler (com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler)1 Row (org.apache.flink.types.Row)1 Test (org.junit.Test)1