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();
}
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();
}
}
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();
}
}
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);
}
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();
}
Aggregations