Search in sources :

Example 1 with VectorToTensor

use of com.alibaba.alink.pipeline.dataproc.VectorToTensor in project Alink by alibaba.

the class Chap25 method dnnReg.

public static void dnnReg(BatchOperator<?> train_set, BatchOperator<?> test_set) throws Exception {
    BatchOperator.setParallelism(1);
    new Pipeline().add(new StandardScaler().setSelectedCols(Chap16.FEATURE_COL_NAMES)).add(new VectorAssembler().setSelectedCols(Chap16.FEATURE_COL_NAMES).setOutputCol("vec")).add(new VectorToTensor().setSelectedCol("vec").setOutputCol("tensor").setReservedCols("quality")).add(new KerasSequentialRegressor().setTensorCol("tensor").setLabelCol("quality").setPredictionCol("pred").setLayers("Dense(64, activation='relu')", "Dense(64, activation='relu')", "Dense(64, activation='relu')", "Dense(64, activation='relu')", "Dense(64, activation='relu')").setNumEpochs(20)).fit(train_set).transform(test_set).lazyPrintStatistics().link(new EvalRegressionBatchOp().setLabelCol("quality").setPredictionCol("pred").lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : StandardScaler(com.alibaba.alink.pipeline.dataproc.StandardScaler) VectorAssembler(com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler) EvalRegressionBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp) KerasSequentialRegressor(com.alibaba.alink.pipeline.regression.KerasSequentialRegressor) VectorToTensor(com.alibaba.alink.pipeline.dataproc.VectorToTensor) Pipeline(com.alibaba.alink.pipeline.Pipeline)

Example 2 with VectorToTensor

use of com.alibaba.alink.pipeline.dataproc.VectorToTensor in project Alink by alibaba.

the class Chap25 method cnn.

public static void cnn(BatchOperator<?> train_set, BatchOperator<?> test_set) throws Exception {
    BatchOperator.setParallelism(1);
    new Pipeline().add(new VectorFunction().setSelectedCol("vec").setFuncName("Scale").setWithVariable(1.0 / 255.0)).add(new VectorToTensor().setTensorDataType("float").setTensorShape(28, 28).setSelectedCol("vec").setOutputCol("tensor").setReservedCols("label")).add(new KerasSequentialClassifier().setTensorCol("tensor").setLabelCol("label").setPredictionCol("pred").setLayers("Reshape((28, 28, 1))", "Conv2D(32, kernel_size=(3, 3), activation='relu')", "MaxPooling2D(pool_size=(2, 2))", "Conv2D(64, kernel_size=(3, 3), activation='relu')", "MaxPooling2D(pool_size=(2, 2))", "Flatten()", "Dropout(0.5)").setNumEpochs(20).setValidationSplit(0.1).setSaveBestOnly(true).setBestMetric("sparse_categorical_accuracy")).fit(train_set).transform(test_set).link(new EvalMultiClassBatchOp().setLabelCol("label").setPredictionCol("pred").lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : KerasSequentialClassifier(com.alibaba.alink.pipeline.classification.KerasSequentialClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) VectorFunction(com.alibaba.alink.pipeline.dataproc.vector.VectorFunction) VectorToTensor(com.alibaba.alink.pipeline.dataproc.VectorToTensor) Pipeline(com.alibaba.alink.pipeline.Pipeline)

Example 3 with VectorToTensor

use of com.alibaba.alink.pipeline.dataproc.VectorToTensor in project Alink by alibaba.

the class Chap25 method dnn.

public static void dnn(BatchOperator<?> train_set, BatchOperator<?> test_set) throws Exception {
    BatchOperator.setParallelism(1);
    new Pipeline().add(new VectorFunction().setSelectedCol("vec").setFuncName("Scale").setWithVariable(1.0 / 255.0)).add(new VectorToTensor().setTensorDataType("float").setSelectedCol("vec").setOutputCol("tensor").setReservedCols("label")).add(new KerasSequentialClassifier().setTensorCol("tensor").setLabelCol("label").setPredictionCol("pred").setLayers("Dense(256, activation='relu')", "Dense(128, activation='relu')").setNumEpochs(50).setBatchSize(512).setValidationSplit(0.1).setSaveBestOnly(true).setBestMetric("sparse_categorical_accuracy")).fit(train_set).transform(test_set).link(new EvalMultiClassBatchOp().setLabelCol("label").setPredictionCol("pred").lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : KerasSequentialClassifier(com.alibaba.alink.pipeline.classification.KerasSequentialClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) VectorFunction(com.alibaba.alink.pipeline.dataproc.vector.VectorFunction) VectorToTensor(com.alibaba.alink.pipeline.dataproc.VectorToTensor) Pipeline(com.alibaba.alink.pipeline.Pipeline)

Aggregations

Pipeline (com.alibaba.alink.pipeline.Pipeline)3 VectorToTensor (com.alibaba.alink.pipeline.dataproc.VectorToTensor)3 EvalMultiClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp)2 KerasSequentialClassifier (com.alibaba.alink.pipeline.classification.KerasSequentialClassifier)2 VectorFunction (com.alibaba.alink.pipeline.dataproc.vector.VectorFunction)2 EvalRegressionBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalRegressionBatchOp)1 StandardScaler (com.alibaba.alink.pipeline.dataproc.StandardScaler)1 VectorAssembler (com.alibaba.alink.pipeline.dataproc.vector.VectorAssembler)1 KerasSequentialRegressor (com.alibaba.alink.pipeline.regression.KerasSequentialRegressor)1