Search in sources :

Example 1 with EvalMultiClassBatchOp

use of com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp in project Alink by alibaba.

the class Chap12 method c_5.

static void c_5() throws Exception {
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    new Softmax().setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).enableLazyPrintTrainInfo().enableLazyPrintModelInfo().fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("Softmax"));
    BatchOperator.execute();
}
Also used : EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) Softmax(com.alibaba.alink.pipeline.classification.Softmax)

Example 2 with EvalMultiClassBatchOp

use of com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp 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 3 with EvalMultiClassBatchOp

use of com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp in project Alink by alibaba.

the class Chap13 method c_6.

static void c_6() 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 KnnClassifier().setK(3).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("KnnClassifier - 3 - EUCLIDEAN"));
    BatchOperator.execute();
    new KnnClassifier().setDistanceType(DistanceType.COSINE).setK(3).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("KnnClassifier - 3 - COSINE"));
    BatchOperator.execute();
    new KnnClassifier().setK(7).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("KnnClassifier - 7 - EUCLIDEAN"));
    BatchOperator.execute();
}
Also used : EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) KnnClassifier(com.alibaba.alink.pipeline.classification.KnnClassifier)

Example 4 with EvalMultiClassBatchOp

use of com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp 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 5 with EvalMultiClassBatchOp

use of com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp in project Alink by alibaba.

the class Chap13 method c_3.

static void c_3() throws Exception {
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + SPARSE_TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + SPARSE_TEST_FILE);
    BatchOperator.setParallelism(1);
    new OneVsRest().setClassifier(new LogisticRegression().setVectorCol(VECTOR_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME)).setNumClass(10).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("OneVsRest - LogisticRegression"));
    new OneVsRest().setClassifier(new LinearSvm().setVectorCol(VECTOR_COL_NAME).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME)).setNumClass(10).fit(train_data).transform(test_data).link(new EvalMultiClassBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("OneVsRest - LinearSvm"));
    BatchOperator.execute();
}
Also used : EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) OneVsRest(com.alibaba.alink.pipeline.classification.OneVsRest) LinearSvm(com.alibaba.alink.pipeline.classification.LinearSvm) LogisticRegression(com.alibaba.alink.pipeline.classification.LogisticRegression)

Aggregations

EvalMultiClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp)27 Test (org.junit.Test)14 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)10 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)7 Row (org.apache.flink.types.Row)7 MultiClassMetrics (com.alibaba.alink.operator.common.evaluation.MultiClassMetrics)6 EvalMultiClassStreamOp (com.alibaba.alink.operator.stream.evaluation.EvalMultiClassStreamOp)4 Pipeline (com.alibaba.alink.pipeline.Pipeline)4 BatchOperator (com.alibaba.alink.operator.batch.BatchOperator)3 Softmax (com.alibaba.alink.pipeline.classification.Softmax)3 Stopwatch (com.alibaba.alink.common.utils.Stopwatch)2 JsonValueBatchOp (com.alibaba.alink.operator.batch.dataproc.JsonValueBatchOp)2 KerasSequentialClassifier (com.alibaba.alink.pipeline.classification.KerasSequentialClassifier)2 KnnClassifier (com.alibaba.alink.pipeline.classification.KnnClassifier)2 LinearSvm (com.alibaba.alink.pipeline.classification.LinearSvm)2 LogisticRegression (com.alibaba.alink.pipeline.classification.LogisticRegression)2 MultilayerPerceptronClassifier (com.alibaba.alink.pipeline.classification.MultilayerPerceptronClassifier)2 OneVsRest (com.alibaba.alink.pipeline.classification.OneVsRest)2 VectorToTensor (com.alibaba.alink.pipeline.dataproc.VectorToTensor)2 VectorFunction (com.alibaba.alink.pipeline.dataproc.vector.VectorFunction)2