use of com.alibaba.alink.operator.batch.classification.LogisticRegressionPredictBatchOp in project Alink by alibaba.
the class Chap08 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);
LogisticRegressionTrainBatchOp lrTrainer = new LogisticRegressionTrainBatchOp().setFeatureCols(FEATURE_COL_NAMES).setLabelCol(LABEL_COL_NAME);
LogisticRegressionPredictBatchOp lrPredictor = new LogisticRegressionPredictBatchOp().setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME);
train_data.link(lrTrainer);
lrPredictor.linkFrom(lrTrainer, test_data);
lrTrainer.lazyPrintTrainInfo().lazyPrintModelInfo();
lrPredictor.lazyPrint(5, "< Prediction >").link(new AkSinkBatchOp().setFilePath(DATA_DIR + LR_PRED_FILE).setOverwriteSink(true));
BatchOperator.execute();
}
use of com.alibaba.alink.operator.batch.classification.LogisticRegressionPredictBatchOp in project Alink by alibaba.
the class Chap10 method c_1.
static void c_1() throws Exception {
BatchOperator<?> train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE).select(CLAUSE_CREATE_FEATURES);
BatchOperator<?> test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE).select(CLAUSE_CREATE_FEATURES);
String[] new_features = ArrayUtils.removeElement(train_data.getColNames(), LABEL_COL_NAME);
train_data.lazyPrint(5, "< new features >");
LogisticRegressionTrainBatchOp trainer = new LogisticRegressionTrainBatchOp().setFeatureCols(new_features).setLabelCol(LABEL_COL_NAME);
LogisticRegressionPredictBatchOp predictor = new LogisticRegressionPredictBatchOp().setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME);
train_data.link(trainer);
predictor.linkFrom(trainer, test_data);
trainer.lazyPrintTrainInfo().lazyCollectTrainInfo(new Consumer<LinearModelTrainInfo>() {
@Override
public void accept(LinearModelTrainInfo linearModelTrainInfo) {
printImportance(linearModelTrainInfo.getColNames(), linearModelTrainInfo.getImportance());
}
});
predictor.link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("2").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics());
BatchOperator.execute();
}
use of com.alibaba.alink.operator.batch.classification.LogisticRegressionPredictBatchOp in project Alink by alibaba.
the class Chap10 method c_2.
static void c_2() throws Exception {
BatchOperator<?> train_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TRAIN_FILE).select(CLAUSE_CREATE_FEATURES);
BatchOperator<?> test_data = new AkSourceBatchOp().setFilePath(DATA_DIR + TEST_FILE).select(CLAUSE_CREATE_FEATURES);
String[] new_features = ArrayUtils.removeElement(train_data.getColNames(), LABEL_COL_NAME);
train_data.lazyPrint(5, "< new features >");
LogisticRegressionTrainBatchOp trainer = new LogisticRegressionTrainBatchOp().setFeatureCols(new_features).setLabelCol(LABEL_COL_NAME).setL1(0.01);
LogisticRegressionPredictBatchOp predictor = new LogisticRegressionPredictBatchOp().setPredictionCol(PREDICTION_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME);
train_data.link(trainer);
predictor.linkFrom(trainer, test_data);
trainer.lazyPrintTrainInfo().lazyCollectTrainInfo(new Consumer<LinearModelTrainInfo>() {
@Override
public void accept(LinearModelTrainInfo linearModelTrainInfo) {
printImportance(linearModelTrainInfo.getColNames(), linearModelTrainInfo.getImportance());
}
});
predictor.link(new EvalBinaryClassBatchOp().setPositiveLabelValueString("2").setLabelCol(LABEL_COL_NAME).setPredictionDetailCol(PRED_DETAIL_COL_NAME).lazyPrintMetrics());
BatchOperator.execute();
}
Aggregations