Search in sources :

Example 1 with CorrelationBatchOp

use of com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp in project Alink by alibaba.

the class Chap12 method c_2.

static void c_2() throws Exception {
    CsvSourceBatchOp source = new CsvSourceBatchOp().setFilePath(DATA_DIR + ORIGIN_FILE).setSchemaStr(SCHEMA_STRING);
    source.lazyPrint(5, "origin file").lazyPrintStatistics("stat of origin file").link(new CorrelationBatchOp().setSelectedCols(FEATURE_COL_NAMES).lazyPrintCorrelation());
    source.groupBy(LABEL_COL_NAME, LABEL_COL_NAME + ", COUNT(*) AS cnt").lazyPrint(-1);
    BatchOperator.execute();
    Utils.splitTrainTestIfNotExist(source, DATA_DIR + TRAIN_FILE, DATA_DIR + TEST_FILE, 0.9);
}
Also used : CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp) CorrelationBatchOp(com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp)

Example 2 with CorrelationBatchOp

use of com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp in project Alink by alibaba.

the class Chap08 method c_3_2.

static void c_3_2() throws Exception {
    CsvSourceBatchOp source = new CsvSourceBatchOp().setFilePath(DATA_DIR + ORIGIN_FILE).setSchemaStr(SCHEMA_STRING);
    CorrelationResult correlation = new CorrelationBatchOp().linkFrom(source).collectCorrelation();
    String[] colNames = correlation.getColNames();
    System.out.print("Correlation of " + colNames[0] + " with " + colNames[1]);
    System.out.println(" is " + correlation.getCorrelation()[0][1]);
    System.out.println(correlation.getCorrelationMatrix());
    source.link(new CorrelationBatchOp().lazyCollectCorrelation(new Consumer<CorrelationResult>() {

        @Override
        public void accept(CorrelationResult correlationResult) {
            String[] colNames = correlationResult.getColNames();
            System.out.print("Correlation of " + colNames[0] + " with " + colNames[1]);
            System.out.println(" is " + correlationResult.getCorrelation()[0][1]);
            System.out.println(correlationResult.getCorrelationMatrix());
        }
    }));
    source.link(new CorrelationBatchOp().lazyPrintCorrelation("< Pearson Correlation >"));
    source.link(new CorrelationBatchOp().setMethod(Method.SPEARMAN).lazyPrintCorrelation("< Spearman Correlation >"));
    BatchOperator.execute();
}
Also used : Consumer(java.util.function.Consumer) CorrelationResult(com.alibaba.alink.operator.common.statistics.basicstatistic.CorrelationResult) CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp) CorrelationBatchOp(com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp)

Example 3 with CorrelationBatchOp

use of com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp in project Alink by alibaba.

the class Chap11 method c_1.

static void c_1() throws Exception {
    BatchOperator<?> source = getSource();
    source.lazyPrint(10, "origin file");
    source.lazyPrintStatistics("stat of origin file");
    source.link(new CorrelationBatchOp().setSelectedCols("user_id", "brand_id", "type").lazyPrintCorrelation());
    source.select("min(ts) AS min_ts, max(ts) AS max_ts").lazyPrint(-1);
    source.groupBy("type", "type, COUNT(*) AS cnt").lazyPrint(-1);
    BatchOperator.execute();
}
Also used : CorrelationBatchOp(com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp)

Example 4 with CorrelationBatchOp

use of com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp in project Alink by alibaba.

the class Chap16 method c_2.

static void c_2() throws Exception {
    CsvSourceBatchOp source = new CsvSourceBatchOp().setFilePath(DATA_DIR + ORIGIN_FILE).setSchemaStr(Utils.generateSchemaString(COL_NAMES, COL_TYPES)).setFieldDelimiter(";").setIgnoreFirstLine(true);
    source.lazyPrint(5);
    source.link(new CorrelationBatchOp().lazyPrintCorrelation());
    source.groupBy(LABEL_COL_NAME, LABEL_COL_NAME + ", COUNT(*) AS cnt").orderBy(LABEL_COL_NAME, 100).lazyPrint(-1);
    BatchOperator.execute();
    Utils.splitTrainTestIfNotExist(source, DATA_DIR + TRAIN_FILE, DATA_DIR + TEST_FILE, 0.8);
}
Also used : CsvSourceBatchOp(com.alibaba.alink.operator.batch.source.CsvSourceBatchOp) CorrelationBatchOp(com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp)

Aggregations

CorrelationBatchOp (com.alibaba.alink.operator.batch.statistics.CorrelationBatchOp)4 CsvSourceBatchOp (com.alibaba.alink.operator.batch.source.CsvSourceBatchOp)3 CorrelationResult (com.alibaba.alink.operator.common.statistics.basicstatistic.CorrelationResult)1 Consumer (java.util.function.Consumer)1