use of com.alibaba.alink.pipeline.feature.QuantileDiscretizerModel in project Alink by alibaba.
the class PipelineSaveAndLoadTest method test2.
@Test
public void test2() throws Exception {
String model_filename = "/tmp/model2.csv";
CsvSourceBatchOp source = new CsvSourceBatchOp().setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFilePath("https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv");
QuantileDiscretizerTrainBatchOp train = new QuantileDiscretizerTrainBatchOp().setNumBuckets(2).setSelectedCols("petal_length").linkFrom(source);
train.link(new AkSinkBatchOp().setFilePath(model_filename).setOverwriteSink(true));
BatchOperator.execute();
// # save pipeline model data to file
String pipelineModelFilename = "/tmp/model23424.csv";
QuantileDiscretizer stage1 = new QuantileDiscretizer().setNumBuckets(2).setSelectedCols("sepal_length");
Binarizer stage2 = new Binarizer().setSelectedCol("petal_width").setThreshold(1.);
AkSourceBatchOp modelData = new AkSourceBatchOp().setFilePath(model_filename);
QuantileDiscretizerModel stage3 = new QuantileDiscretizerModel().setSelectedCols("petal_length").setModelData(modelData);
PipelineModel prevPipelineModel = new Pipeline(stage1, stage2, stage3).fit(source);
prevPipelineModel.save(pipelineModelFilename, true);
BatchOperator.execute();
}
use of com.alibaba.alink.pipeline.feature.QuantileDiscretizerModel in project Alink by alibaba.
the class PipelineSaveAndLoadTest method testPipelineModelLoadSaveNested.
@Test
public void testPipelineModelLoadSaveNested() throws Exception {
CsvSourceBatchOp source = new CsvSourceBatchOp().setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFilePath("https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv");
String pipeline_model_filename = "/tmp/model123.csv";
QuantileDiscretizerModel model1 = new QuantileDiscretizer().setNumBuckets(2).setSelectedCols("sepal_length").fit(source);
Binarizer model2 = new Binarizer().setSelectedCol("petal_width").setThreshold(1.);
PipelineModel pipeline_model = new PipelineModel(model1, model2);
pipeline_model.save(pipeline_model_filename, true);
BatchOperator.execute();
pipeline_model = PipelineModel.load(pipeline_model_filename);
BatchOperator<?> res = pipeline_model.transform(source);
res.print();
}
use of com.alibaba.alink.pipeline.feature.QuantileDiscretizerModel in project Alink by alibaba.
the class PipelineSaveAndLoadTest method test3.
@Test
public void test3() throws Exception {
// # save model data to file (ModelBase)
String modelFilename = "/tmp/model12341.csv";
CsvSourceBatchOp source = new CsvSourceBatchOp().setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFilePath("https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv");
new QuantileDiscretizer().setNumBuckets(2).setSelectedCols("petal_length").fit(source).getModelData().link(new CsvSinkBatchOp().setFilePath(modelFilename).setOverwriteSink(true));
BatchOperator.execute();
// # save pipeline model data to file
QuantileDiscretizerModel model1 = new QuantileDiscretizer().setNumBuckets(2).setSelectedCols("sepal_length").fit(source);
Binarizer model2 = new Binarizer().setSelectedCol("petal_width").setThreshold(1.);
CsvSourceBatchOp modelData = new CsvSourceBatchOp().setFilePath(modelFilename).setSchemaStr("model_id BIGINT, model_info STRING");
QuantileDiscretizerModel model3 = new QuantileDiscretizerModel().setSelectedCols("petal_length").setModelData(modelData);
CsvSourceStreamOp streamSource = new CsvSourceStreamOp().setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFilePath("https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv");
PipelineModel pipelineModel = new PipelineModel(model1, model2, model3);
pipelineModel = PipelineModel.collectLoad(pipelineModel.save());
pipelineModel.transform(streamSource).print();
StreamOperator.execute();
}
use of com.alibaba.alink.pipeline.feature.QuantileDiscretizerModel in project Alink by alibaba.
the class PipelineTest method test.
@Test
public void test() throws Exception {
CsvSourceBatchOp source = new CsvSourceBatchOp().setSchemaStr("sepal_length double, sepal_width double, petal_length double, petal_width double, category string").setFilePath("https://alink-test-data.oss-cn-hangzhou.aliyuncs.com/iris.csv");
String pipeline_model_filename = "/tmp/model123123123123.csv";
QuantileDiscretizerModel model1 = new QuantileDiscretizer().setNumBuckets(2).setSelectedCols("sepal_length").fit(source);
Binarizer model2 = new Binarizer().setSelectedCol("petal_width").setThreshold(1.);
PipelineModel pipeline_model = new PipelineModel(model1, model2);
pipeline_model.save(pipeline_model_filename, true);
BatchOperator.execute();
pipeline_model = PipelineModel.load(pipeline_model_filename);
BatchOperator<?> res = pipeline_model.transform(source);
res.print();
}
Aggregations