lindong28 commented on code in PR #100: URL: https://github.com/apache/flink-ml/pull/100#discussion_r874531297
########## flink-ml-benchmark/src/main/resources/naivebayes-benchmark.json: ########## @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +{ + "version": 1, + "NaiveBayes": { + "stage": { + "className": "org.apache.flink.ml.classification.naivebayes.NaiveBayes", + "paramMap": { + "smoothing": 1.0, + "featuresCol": "features", + "predictionCol": "prediction", + "labelCol": "label", + "modelType": "multinomial" + } + }, + "inputData": { + "className": "org.apache.flink.ml.benchmark.datagenerator.common.LabeledPointWithWeightGenerator", + "paramMap": { + "seed": 2, + "featuresCol": "features", Review Comment: Instead of asking users to specify featuresCol, weightCol and labelCol, would it be simpler to let user just specify `colNames = ["features,weight,label"]`? ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + + public static final Param<Integer> FEATURE_ARITY = + new IntParam( + "featureArity", + "Arity of each feature. " + + "If set to positive value, each feature would be an integer in range [0, arity - 1]. " + + "If set to zero, each feature would be a continuous double in range [0, 1).", + 2, + ParamValidators.gtEq(0)); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, the label would be an integer in range [0, arity - 1]. " + + "If set to zero, the label would be a continuous double in range [0, 1).", + 2, + ParamValidators.gtEq(0)); + + public static final Param<Integer> WEIGHT_ARITY = + new IntParam( + "weightArity", + "Arity of weight. " + + "If set to positive value, the weight would be an integer in range [1, arity]. " + + "If set to zero, weight would be a continuous double in range [0, 1).", + 1, + ParamValidators.gtEq(0)); + + private final Map<Param<?>, Object> paramMap = new HashMap<>(); + + public LabeledPointWithWeightGenerator() { + ParamUtils.initializeMapWithDefaultValues(paramMap, this); + } + + public int getFeatureArity() { + return get(FEATURE_ARITY); + } + + public LabeledPointWithWeightGenerator setFeatureArity(int value) { + return set(FEATURE_ARITY, value); + } + + public int getLabelArity() { + return get(LABEL_ARITY); + } + + public LabeledPointWithWeightGenerator setLabelArity(int value) { + return set(LABEL_ARITY, value); + } + + public int getWeightArity() { + return get(WEIGHT_ARITY); + } + + public LabeledPointWithWeightGenerator setWeightArity(int value) { + return set(WEIGHT_ARITY, value); + } + + @Override + public Table[] getData(StreamTableEnvironment tEnv) { + StreamExecutionEnvironment env = TableUtils.getExecutionEnvironment(tEnv); + + DataStream<Row> dataStream = + env.fromParallelCollection( + new NumberSequenceIterator(1L, getNumValues()), + BasicTypeInfo.LONG_TYPE_INFO) + .map( + new RandomLabeledPointWithWeightGenerator( + getSeed(), + getVectorDim(), + getFeatureArity(), + getLabelArity(), + getWeightArity()), + new RowTypeInfo( + new TypeInformation[] { + DenseVectorTypeInfo.INSTANCE, Types.DOUBLE, Types.DOUBLE + }, + new String[] { + getFeaturesCol(), getLabelCol(), getWeightCol() + })); + + Table dataTable = tEnv.fromDataStream(dataStream); Review Comment: Should this class handle the `colNames` parameter? Currently `DenseVectorArrayGenerator` checks that `getColNames().length > 0` when this parameter value is not null. Would it be better to verify `getColNames().length == 1` in this case? And we probably also need to take care of the case where the string contains `,` since this is a common-separated string. Can you update `DenseVectorGenerator` as well for consistency? I am also wondering if it would be more intuitive to update the description of `colNames` to be `An array of common-separated strings representing field names of the generated tables`. ########## flink-ml-benchmark/src/main/resources/naivebayes-benchmark.json: ########## @@ -0,0 +1,44 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +{ + "version": 1, + "NaiveBayes": { + "stage": { + "className": "org.apache.flink.ml.classification.naivebayes.NaiveBayes", + "paramMap": { + "smoothing": 1.0, + "featuresCol": "features", Review Comment: Do you think it would make user experience better by skipping parameters whose value is the same as the default value in the config file? ########## flink-ml-benchmark/src/main/java/org/apache/flink/ml/benchmark/datagenerator/common/LabeledPointWithWeightGenerator.java: ########## @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.ml.benchmark.datagenerator.common; + +import org.apache.flink.api.common.functions.RichMapFunction; +import org.apache.flink.api.common.typeinfo.BasicTypeInfo; +import org.apache.flink.api.common.typeinfo.TypeInformation; +import org.apache.flink.api.common.typeinfo.Types; +import org.apache.flink.api.java.tuple.Tuple2; +import org.apache.flink.api.java.typeutils.RowTypeInfo; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.ml.benchmark.datagenerator.InputDataGenerator; +import org.apache.flink.ml.benchmark.datagenerator.param.HasVectorDim; +import org.apache.flink.ml.common.datastream.TableUtils; +import org.apache.flink.ml.common.param.HasFeaturesCol; +import org.apache.flink.ml.common.param.HasLabelCol; +import org.apache.flink.ml.common.param.HasWeightCol; +import org.apache.flink.ml.linalg.Vectors; +import org.apache.flink.ml.linalg.typeinfo.DenseVectorTypeInfo; +import org.apache.flink.ml.param.IntParam; +import org.apache.flink.ml.param.Param; +import org.apache.flink.ml.param.ParamValidators; +import org.apache.flink.ml.util.ParamUtils; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.table.api.Table; +import org.apache.flink.table.api.bridge.java.StreamTableEnvironment; +import org.apache.flink.types.Row; +import org.apache.flink.util.NumberSequenceIterator; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +/** A DataGenerator which creates a table of features, label and weight. */ +public class LabeledPointWithWeightGenerator + implements InputDataGenerator<LabeledPointWithWeightGenerator>, + HasFeaturesCol<LabeledPointWithWeightGenerator>, + HasLabelCol<LabeledPointWithWeightGenerator>, + HasWeightCol<LabeledPointWithWeightGenerator>, + HasVectorDim<LabeledPointWithWeightGenerator> { + + public static final Param<Integer> FEATURE_ARITY = + new IntParam( + "featureArity", + "Arity of each feature. " + + "If set to positive value, each feature would be an integer in range [0, arity - 1]. " + + "If set to zero, each feature would be a continuous double in range [0, 1).", + 2, + ParamValidators.gtEq(0)); + + public static final Param<Integer> LABEL_ARITY = + new IntParam( + "labelArity", + "Arity of label. " + + "If set to positive value, the label would be an integer in range [0, arity - 1]. " + + "If set to zero, the label would be a continuous double in range [0, 1).", + 2, + ParamValidators.gtEq(0)); + + public static final Param<Integer> WEIGHT_ARITY = Review Comment: For benchmark, should we always generate weight as a random value in range [0, 1)? If not, what would be the other use-cases? If yes, maybe we can remove this parameter? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org