Search in sources :

Example 1 with MultilayerPerceptronClassifier

use of com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier in project Alink by alibaba.

the class Chap12 method c_6.

static void c_6() throws Exception {
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    new MultilayerPerceptronClassifier().setLayers(new int[] { 4, 12, 3 }).setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("MultilayerPerceptronClassifier [4, 12, 3]"));
    new MultilayerPerceptronClassifier().setLayers(new int[] { 4, 3 }).setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("MultilayerPerceptronClassifier [4, 3]"));
    BatchOperator.execute();
}
Also used : MultilayerPerceptronClassifier(com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp)

Example 2 with MultilayerPerceptronClassifier

use of com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier in project Alink by alibaba.

the class Chap13 method c_4.

static void c_4() throws Exception {
    BatchOperator.setParallelism(4);
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + SPARSE_TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + SPARSE_TEST_FILE);
    new MultilayerPerceptronClassifier().setLayers(new int[] { 784, 10 }).setVectorCol(VECTOR_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("MultilayerPerceptronClassifier {784, 10}"));
    BatchOperator.execute();
    new MultilayerPerceptronClassifier().setLayers(new int[] { 784, 256, 128, 10 }).setVectorCol(VECTOR_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("MultilayerPerceptronClassifier {784, 256, 128, 10}"));
    BatchOperator.execute();
}
Also used : MultilayerPerceptronClassifier(com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp)

Example 3 with MultilayerPerceptronClassifier

use of com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier in project Alink by alibaba.

the class ModelSaveAndLoadTest method testSaveLoadSave.

@Test
public void testSaveLoadSave() throws Exception {
    VectorAssembler va = new VectorAssembler().setSelectedCols(Iris.getFeatureColNames()).setOutputCol("features");
    MultilayerPerceptronClassifier classifier = new MultilayerPerceptronClassifier().setVectorCol("features").setLabelCol(Iris.getLabelColName()).setLayers(new int[] { 4, 5, 3 }).setMaxIter(30).setPredictionCol("pred_label").setPredictionDetailCol("pred_detail").setReservedCols(Iris.getLabelColName());
    Pipeline pipeline = new Pipeline().add(va).add(classifier);
    PipelineModel model = PipelineModel.collectLoad(pipeline.fit(data).save());
    LocalPredictor localPredictor = model.collectLocalPredictor(data.getSchema());
    Row pred = localPredictor.map(Row.of(4.8, 3.4, 1.9, 0.2, "Iris-setosa"));
    Assert.assertEquals(pred.getArity(), 3);
}
Also used : MultilayerPerceptronClassifier(com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier) VectorAssembler(com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 4 with MultilayerPerceptronClassifier

use of com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier in project Alink by alibaba.

the class PipelineSaveAndLoadTest method testSaveLoadSave.

@Test
public void testSaveLoadSave() throws Exception {
    VectorAssembler va = new VectorAssembler().setSelectedCols(Iris.getFeatureColNames()).setOutputCol("features");
    MultilayerPerceptronClassifier classifier = new MultilayerPerceptronClassifier().setVectorCol("features").setLabelCol(Iris.getLabelColName()).setLayers(new int[] { 4, 5, 3 }).setMaxIter(30).setPredictionCol("pred_label").setPredictionDetailCol("pred_detail").setReservedCols(Iris.getLabelColName());
    Pipeline pipeline = new Pipeline().add(va).add(classifier);
    Pipeline pipeline1 = Pipeline.collectLoad(pipeline.save());
    PipelineModel model = PipelineModel.collectLoad(pipeline1.fit(data).save());
    LocalPredictor localPredictor = model.collectLocalPredictor(data.getSchema());
    Row pred = localPredictor.map(Row.of(4.8, 3.4, 1.9, 0.2, "Iris-setosa"));
    Assert.assertEquals(pred.getArity(), 3);
}
Also used : MultilayerPerceptronClassifier(com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier) VectorAssembler(com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 5 with MultilayerPerceptronClassifier

use of com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier in project Alink by alibaba.

the class PipelineSaveAndLoadTest method testNewSave.

@Test
public void testNewSave() throws Exception {
    VectorAssembler va = new VectorAssembler().setSelectedCols(Iris.getFeatureColNames()).setOutputCol("features");
    MultilayerPerceptronClassifier classifier = new MultilayerPerceptronClassifier().setVectorCol("features").setLabelCol(Iris.getLabelColName()).setLayers(new int[] { 4, 5, 3 }).setMaxIter(30).setPredictionCol("pred_label").setPredictionDetailCol("pred_detail").setReservedCols(Iris.getLabelColName());
    Pipeline pipeline = new Pipeline().add(va).add(classifier);
    PipelineModel model = pipeline.fit(data);
    BatchOperator<?> saved = model.save();
    PipelineModel modelLoaded = PipelineModel.collectLoad(saved);
    Assert.assertEquals(modelLoaded.transform(Iris.getBatchData()).count(), 150);
}
Also used : MultilayerPerceptronClassifier(com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier) VectorAssembler(com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler) Test(org.junit.Test)

Aggregations

MultilayerPerceptronClassifier (com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier)11 VectorAssembler (com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler)9 Test (org.junit.Test)9 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)4 Row (org.apache.flink.types.Row)4 DenseVector (com.alibaba.alink.common.linalg.DenseVector)2 EvalMultiClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp)2 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)2 TableSchema (org.apache.flink.table.api.TableSchema)2