Search in sources :

Example 1 with EvalRegressionBatchOp

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

the class Chap16 method c_3.

static void c_3() throws Exception {
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    new LinearRegression().setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).enableLazyPrintTrainInfo().enableLazyPrintModelInfo().fit(train_data).transform(test_data).link(new EvalRegressionBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("LinearRegression"));
    new LassoRegression().setLambda(0.05).setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).enableLazyPrintTrainInfo().enableLazyPrintModelInfo("< LASSO model >").fit(train_data).transform(test_data).link(new EvalRegressionBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("LassoRegression"));
    BatchOperator.execute();
}
Also used : LassoRegression(com.alibaba.alink.pipeline.regression.LassoRegression) AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) LinearRegression(com.alibaba.alink.pipeline.regression.LinearRegression)

Example 2 with EvalRegressionBatchOp

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

the class Chap16 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);
    for (int numTrees : new int[] { 16, 32, 64, 128, 256, 512 }) {
        new GbdtRegressor().setLearningRate(0.05).setMaxLeaves(256).setFeatureSubsamplingRatio(0.3).setMinSamplesPerLeaf(2).setMaxDepth(100).setNumTrees(numTrees).setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalRegressionBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("GbdtRegressor - " + numTrees));
        BatchOperator.execute();
    }
}
Also used : AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) GbdtRegressor(com.alibaba.alink.pipeline.regression.GbdtRegressor)

Example 3 with EvalRegressionBatchOp

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

the class Chap16 method c_4.

static void c_4() throws Exception {
    AkSourceBatchOp train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE);
    AkSourceBatchOp test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE);
    new DecisionTreeRegressor().setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalRegressionBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("DecisionTreeRegressor"));
    BatchOperator.execute();
    for (int numTrees : new int[] { 2, 4, 8, 16, 32, 64, 128 }) {
        new RandomForestRegressor().setNumTrees(numTrees).setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).fit(train_data).transform(test_data).link(new EvalRegressionBatchOp().setLabelCol(LABEL_COL_NAME).setPredictionCol(PREDICTION_COL_NAME).lazyPrintMetrics("RandomForestRegressor - " + numTrees));
        BatchOperator.execute();
    }
}
Also used : AkSourceBatchOp(com.alibaba.alink.operator.batch.source.AkSourceBatchOp) DecisionTreeRegressor(com.alibaba.alink.pipeline.regression.DecisionTreeRegressor) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) RandomForestRegressor(com.alibaba.alink.pipeline.regression.RandomForestRegressor)

Example 4 with EvalRegressionBatchOp

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

the class RandomForestTrainBatchOpTest method linkFromDecisionTreeModeParallel.

@Test
public void linkFromDecisionTreeModeParallel() throws Exception {
    Row[] testArray = new Row[] { Row.of(1, 2, 0.8), Row.of(1, 2, 0.7), Row.of(0, 3, 0.4), Row.of(0, 2, 0.4), Row.of(1, 3, 0.6), Row.of(4, 3, 0.2), Row.of(4, 4, 0.3) };
    String[] colNames = new String[] { "col0", "col1", "label" };
    MemSourceBatchOp memSourceBatchOp = new MemSourceBatchOp(Arrays.asList(testArray), colNames);
    DecisionTreeRegTrainBatchOp decisionTreeRegTrainBatchOp = new DecisionTreeRegTrainBatchOp().setLabelCol(colNames[2]).setFeatureCols(colNames[0], colNames[1]).setCategoricalCols(colNames[1]).setMinSamplesPerLeaf(1).setMaxDepth(4).setMaxMemoryInMB(1).setCreateTreeMode("parallel");
    DecisionTreeRegPredictBatchOp decisionTreeRegPredictBatchOp = new DecisionTreeRegPredictBatchOp().setPredictionCol("pred");
    decisionTreeRegPredictBatchOp.linkFrom(decisionTreeRegTrainBatchOp.linkFrom(memSourceBatchOp), memSourceBatchOp).lazyCollect();
    EvalRegressionBatchOp eval = new EvalRegressionBatchOp().setLabelCol(colNames[2]).setPredictionCol("pred");
    Assert.assertEquals(new RegressionMetrics(decisionTreeRegPredictBatchOp.linkFrom(decisionTreeRegTrainBatchOp.linkFrom(memSourceBatchOp), memSourceBatchOp).linkTo(eval).collect().get(0)).getRmse(), 0.026726, 1e-6);
}
Also used : MemSourceBatchOp(com.alibaba.alink.operator.batch.source.MemSourceBatchOp) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) RegressionMetrics(com.alibaba.alink.operator.common.evaluation.RegressionMetrics) DecisionTreeRegPredictBatchOp(com.alibaba.alink.operator.batch.regression.DecisionTreeRegPredictBatchOp) Row(org.apache.flink.types.Row) DecisionTreeRegTrainBatchOp(com.alibaba.alink.operator.batch.regression.DecisionTreeRegTrainBatchOp) Test(org.junit.Test)

Example 5 with EvalRegressionBatchOp

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

the class RandomForestTrainBatchOpTest method testCartReg.

@Test
public void testCartReg() throws Exception {
    CartRegTrainBatchOp cartRegBatchOp = new CartRegTrainBatchOp().setFeatureCols(featureColNames).setCategoricalCols(categoricalColNames).setLabelCol(colNames[5]);
    CartRegPredictBatchOp cartRegPredictBatchOp = new CartRegPredictBatchOp().setReservedCols(new String[] { colNames[5] }).setPredictionCol("cart_reg_predict_result");
    EvalRegressionBatchOp evalClassificationBatchOp = new EvalRegressionBatchOp().setLabelCol(colNames[5]).setPredictionCol("cart_reg_predict_result");
    CartRegPredictStreamOp cartRegPredictStreamOp = new CartRegPredictStreamOp(cartRegBatchOp).setPredictionCol("cart_reg_predict_result");
    BatchOperator<?> cartRegModel = input.linkTo(cartRegBatchOp);
    BatchOperator<?> cartRegPred = cartRegPredictBatchOp.linkFrom(cartRegModel, input);
    cartRegPred.collect();
    BatchOperator<?> evalResult = evalClassificationBatchOp.linkFrom(cartRegPred);
    evalResult.collect();
    cartRegPredictStreamOp.linkFrom(inputStream);
    MLEnvironmentFactory.getDefault().getStreamExecutionEnvironment().execute();
}
Also used : CartRegTrainBatchOp(com.alibaba.alink.operator.batch.regression.CartRegTrainBatchOp) CartRegPredictBatchOp(com.alibaba.alink.operator.batch.regression.CartRegPredictBatchOp) CartRegPredictStreamOp(com.alibaba.alink.operator.stream.regression.CartRegPredictStreamOp) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) Test(org.junit.Test)

Aggregations

EvalRegressionBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp)14 Test (org.junit.Test)7 Row (org.apache.flink.types.Row)6 MemSourceBatchOp (com.alibaba.alink.operator.batch.source.MemSourceBatchOp)5 RegressionMetrics (com.alibaba.alink.operator.common.evaluation.RegressionMetrics)5 AkSourceBatchOp (com.alibaba.alink.operator.batch.source.AkSourceBatchOp)4 MTable (com.alibaba.alink.common.MTable)2 DecisionTreeRegPredictBatchOp (com.alibaba.alink.operator.batch.regression.DecisionTreeRegPredictBatchOp)2 DecisionTreeRegTrainBatchOp (com.alibaba.alink.operator.batch.regression.DecisionTreeRegTrainBatchOp)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AlsTrainBatchOp (com.alibaba.alink.operator.batch.recommendation.AlsTrainBatchOp)1 CartRegPredictBatchOp (com.alibaba.alink.operator.batch.regression.CartRegPredictBatchOp)1 CartRegTrainBatchOp (com.alibaba.alink.operator.batch.regression.CartRegTrainBatchOp)1 GlmPredictBatchOp (com.alibaba.alink.operator.batch.regression.GlmPredictBatchOp)1 GlmTrainBatchOp (com.alibaba.alink.operator.batch.regression.GlmTrainBatchOp)1 RandomForestRegPredictBatchOp (com.alibaba.alink.operator.batch.regression.RandomForestRegPredictBatchOp)1 RandomForestRegTrainBatchOp (com.alibaba.alink.operator.batch.regression.RandomForestRegTrainBatchOp)1 AkSinkBatchOp (com.alibaba.alink.operator.batch.sink.AkSinkBatchOp)1 TsvSourceBatchOp (com.alibaba.alink.operator.batch.source.TsvSourceBatchOp)1