You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/11/23 02:51:38 UTC

[GitHub] [flink-ml] jiangxin369 opened a new pull request, #180: [FLINK-30159] Add Transformer for ANOVATest

jiangxin369 opened a new pull request, #180:
URL: https://github.com/apache/flink-ml/pull/180

   <!--
   *Thank you very much for contributing to Apache Flink ML - we are happy that you want to help us improve Flink ML. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to one [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] Title of the pull request`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   
   Add Transformer for ANOVATest.
   
   ## Brief change log
   
     - Adds shared parameter `HaSFlatten`
     - Adds Transformer implementation of ANOVATest in Java.
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): ( no)
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes)
     - If yes, how is the feature documented? (JavaDocs)
   


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] yunfengzhou-hub commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
yunfengzhou-hub commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031973100


##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,410 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;
+    private static final List<Row> DENSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.85956061,
+                                    0.1645695,
+                                    0.48347596,
+                                    0.92102727,
+                                    0.42855644,
+                                    0.05746009)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.92500743,
+                                    0.65760154,
+                                    0.13295284,
+                                    0.53344893,
+                                    0.8994776,
+                                    0.24836496)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.03017182,
+                                    0.07244715,
+                                    0.87416449,
+                                    0.55843035,
+                                    0.91604736,
+                                    0.63346045)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.28325261,
+                                    0.36536881,
+                                    0.09223386,
+                                    0.37251258,
+                                    0.34742278,
+                                    0.70517077)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.64850904,
+                                    0.04090877,
+                                    0.21173176,
+                                    0.00148992,
+                                    0.13897166,
+                                    0.21182539)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.02609493,
+                                    0.44608735,
+                                    0.23910531,
+                                    0.95449222,
+                                    0.90763182,
+                                    0.8624905)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.09158744,
+                                    0.97745235,
+                                    0.41150139,
+                                    0.45830467,
+                                    0.52590925,
+                                    0.29441554)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.97211594,
+                                    0.1814442,
+                                    0.30340642,
+                                    0.17445413,
+                                    0.52756958,
+                                    0.02069296)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.06354593,
+                                    0.63527231,
+                                    0.49620335,
+                                    0.0141264,
+                                    0.62722219,
+                                    0.63497507)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.10814149,
+                                    0.8296426,
+                                    0.51775217,
+                                    0.57068344,
+                                    0.54633305,
+                                    0.12714921)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.72731796,
+                                    0.94010124,
+                                    0.45007811,
+                                    0.87650674,
+                                    0.53735565,
+                                    0.49568415)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.41827208,
+                                    0.85100628,
+                                    0.38685271,
+                                    0.60689503,
+                                    0.21784097,
+                                    0.91294433)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.65843656,
+                                    0.5880859,
+                                    0.18862706,
+                                    0.856398,
+                                    0.18029327,
+                                    0.94851926)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.3841634,
+                                    0.25138793,
+                                    0.96746644,
+                                    0.77048045,
+                                    0.44685196,
+                                    0.19813854)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.65982267,
+                                    0.23024125,
+                                    0.13598434,
+                                    0.60144265,
+                                    0.57848927,
+                                    0.85623564)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.35764189,
+                                    0.47623815,
+                                    0.5459232,
+                                    0.79508298,
+                                    0.14462443,
+                                    0.01802919)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.38532153,
+                                    0.90614554,
+                                    0.86629571,
+                                    0.13988735,
+                                    0.32062385,
+                                    0.00179492)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.2142368,
+                                    0.28306022,
+                                    0.59481646,
+                                    0.42567028,
+                                    0.52207663,
+                                    0.78082401)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.20788283,
+                                    0.76861782,
+                                    0.59595468,
+                                    0.62103642,
+                                    0.17781246,
+                                    0.77655345)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.1751708,
+                                    0.4547537,
+                                    0.46187865,
+                                    0.79781199,
+                                    0.05104487,
+                                    0.42406092)));
+
+    private static final List<Row> SPARSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(3, Vectors.dense(6.0, 7.0, 0.0, 7.0, 6.0, 0.0, 0.0).toSparse()),
+                    Row.of(1, Vectors.dense(0.0, 9.0, 6.0, 0.0, 5.0, 9.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(0.0, 9.0, 3.0, 0.0, 5.0, 5.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(0.0, 9.0, 8.0, 5.0, 6.0, 4.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(8.0, 9.0, 6.0, 5.0, 4.0, 4.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(Double.NaN, 9.0, 6.0, 4.0, 0.0, 0.0, 0.0).toSparse()));
+
+    private static final Row EXPECTED_OUTPUT =
+            Row.of(
+                    Vectors.dense(
+                            0.64137831, 0.14830724, 0.69858474, 0.28038169, 0.86759161, 0.81608606),
+                    new long[] {19, 19, 19, 19, 19, 19},
+                    Vectors.dense(
+                            0.64110932, 1.98689258, 0.55499714, 1.40340562, 0.30881722, 0.3848595));
+
+    private static final List<Row> EXPECTED_FLATTENED_OUTPUT =

Review Comment:
   nit: Let's rename these variables to `EXPECTED_OUTPUT_DENSE` and `EXPECTED_FLATTENED_OUTPUT_DENSE`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031142739


##########
flink-ml-python/pyflink/ml/lib/tests/test_ml_lib_completeness.py:
##########
@@ -140,6 +145,11 @@ def module(self):
         from pyflink.ml.lib import stats
         return stats
 
+    def exclude_java_stage(self) -> List[str]:
+        return [
+            "org.apache.flink.ml.stats.anovatest.ANOVATest",

Review Comment:
   We can simplify it to `"anovatest.ANOVATest"` but not `"ANOVATest"`, because it is not required to keep the package name equalsIgnoreCase the class name, that's why we have both `_java_transformer_package_name` and `_java_transformer_class_name` in  class `JavaFeatureTransformer`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031178423


##########
flink-ml-python/pyflink/ml/lib/tests/test_ml_lib_completeness.py:
##########
@@ -81,6 +83,9 @@ def module_name(self):
     def module(self):
         pass
 
+    def exclude_java_stage(self):

Review Comment:
   I don't think we need to add a comment to a test method that is not difficult to understand. For those java stages that have no corresponding python implementation



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] yunfengzhou-hub commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
yunfengzhou-hub commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031101109


##########
flink-ml-python/pyflink/ml/lib/tests/test_ml_lib_completeness.py:
##########
@@ -140,6 +145,11 @@ def module(self):
         from pyflink.ml.lib import stats
         return stats
 
+    def exclude_java_stage(self) -> List[str]:
+        return [
+            "org.apache.flink.ml.stats.anovatest.ANOVATest",

Review Comment:
   Is it possible to simplify it to `"anovatest.ANOVATest"` or `"ANOVATest"`? The test class has enough information to derive the root java package name. 



##########
flink-ml-python/pyflink/ml/lib/tests/test_ml_lib_completeness.py:
##########
@@ -81,6 +83,9 @@ def module_name(self):
     def module(self):
         pass
 
+    def exclude_java_stage(self):

Review Comment:
   Let's add a comment here, describing why we need this method and which java stages should be excluded.



##########
flink-ml-lib/src/main/java/org/apache/flink/ml/stats/anovatest/ANOVATest.java:
##########
@@ -0,0 +1,276 @@
+/*
+ * 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.stats.anovatest;
+
+import org.apache.flink.api.common.functions.AggregateFunction;
+import org.apache.flink.api.common.functions.FlatMapFunction;
+import org.apache.flink.api.common.functions.MapFunction;
+import org.apache.flink.api.common.typeinfo.Types;
+import org.apache.flink.api.java.tuple.Tuple2;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.ml.api.AlgoOperator;
+import org.apache.flink.ml.common.datastream.DataStreamUtils;
+import org.apache.flink.ml.common.param.HasFlatten;
+import org.apache.flink.ml.linalg.DenseVector;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.typeinfo.VectorTypeInfo;
+import org.apache.flink.ml.param.Param;
+import org.apache.flink.ml.util.ParamUtils;
+import org.apache.flink.ml.util.ReadWriteUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+import org.apache.flink.table.api.internal.TableImpl;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Preconditions;
+
+import org.apache.commons.math3.distribution.FDistribution;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.IntStream;
+
+/**
+ * An AlgoOperator which implements the ANOVA test algorithm.
+ *
+ * <p>See <a href="https://en.wikipedia.org/wiki/Analysis_of_variance">Wikipedia</a> for more
+ * information on ANOVA test.
+ *
+ * <p>The input of this algorithm is a table containing a labelColumn of numerical type and a
+ * featuresColumn of vector type. Each index in the input vector represents a feature to be tested.
+ * By default, the output of this algorithm is a table containing a single row with the following
+ * columns, each of which has one value per feature.
+ *
+ * <ul>
+ *   <li>"pValues": vector
+ *   <li>"degreesOfFreedom": int array
+ *   <li>"fValues": vector
+ * </ul>
+ *
+ * <p>The output of this algorithm can be flattened to multiple rows by setting {@link
+ * HasFlatten#FLATTEN} to true, which would contain the following columns:
+ *
+ * <ul>
+ *   <li>"featureIndex": int
+ *   <li>"pValue": double
+ *   <li>"degreeOfFreedom": int
+ *   <li>"fValues": double
+ * </ul>
+ */
+public class ANOVATest implements AlgoOperator<ANOVATest>, ANOVATestParams<ANOVATest> {
+
+    private final Map<Param<?>, Object> paramMap = new HashMap<>();
+
+    public ANOVATest() {
+        ParamUtils.initializeMapWithDefaultValues(paramMap, this);
+    }
+
+    @Override
+    public Table[] transform(Table... inputs) {
+        Preconditions.checkArgument(inputs.length == 1);
+
+        final String featuresCol = getFeaturesCol();
+        final String labelCol = getLabelCol();
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) inputs[0]).getTableEnvironment();
+
+        DataStream<Tuple2<Vector, Double>> inputData =
+                tEnv.toDataStream(inputs[0])
+                        .map(
+                                (MapFunction<Row, Tuple2<Vector, Double>>)
+                                        row -> {
+                                            Number number = (Number) row.getField(labelCol);
+                                            Preconditions.checkNotNull(
+                                                    number, "Input data must contain label value.");
+                                            return new Tuple2<>(
+                                                    ((Vector) row.getField(featuresCol)),
+                                                    number.doubleValue());
+                                        })
+                        .returns(Types.TUPLE(VectorTypeInfo.INSTANCE, Types.DOUBLE));
+        DataStream<List<Row>> streamWithANOVA =
+                DataStreamUtils.aggregate(inputData, new ANOVAAggregator());
+        return new Table[] {convertToTable(tEnv, streamWithANOVA, getFlatten())};
+    }
+
+    /** Computes the pValues and fValues of input features. */

Review Comment:
   This function computes degrees of freedom as well.



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;
+    private static final List<Row> DENSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.85956061,
+                                    0.1645695,
+                                    0.48347596,
+                                    0.92102727,
+                                    0.42855644,
+                                    0.05746009)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.92500743,
+                                    0.65760154,
+                                    0.13295284,
+                                    0.53344893,
+                                    0.8994776,
+                                    0.24836496)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.03017182,
+                                    0.07244715,
+                                    0.87416449,
+                                    0.55843035,
+                                    0.91604736,
+                                    0.63346045)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.28325261,
+                                    0.36536881,
+                                    0.09223386,
+                                    0.37251258,
+                                    0.34742278,
+                                    0.70517077)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.64850904,
+                                    0.04090877,
+                                    0.21173176,
+                                    0.00148992,
+                                    0.13897166,
+                                    0.21182539)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.02609493,
+                                    0.44608735,
+                                    0.23910531,
+                                    0.95449222,
+                                    0.90763182,
+                                    0.8624905)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.09158744,
+                                    0.97745235,
+                                    0.41150139,
+                                    0.45830467,
+                                    0.52590925,
+                                    0.29441554)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.97211594,
+                                    0.1814442,
+                                    0.30340642,
+                                    0.17445413,
+                                    0.52756958,
+                                    0.02069296)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.06354593,
+                                    0.63527231,
+                                    0.49620335,
+                                    0.0141264,
+                                    0.62722219,
+                                    0.63497507)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.10814149,
+                                    0.8296426,
+                                    0.51775217,
+                                    0.57068344,
+                                    0.54633305,
+                                    0.12714921)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.72731796,
+                                    0.94010124,
+                                    0.45007811,
+                                    0.87650674,
+                                    0.53735565,
+                                    0.49568415)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.41827208,
+                                    0.85100628,
+                                    0.38685271,
+                                    0.60689503,
+                                    0.21784097,
+                                    0.91294433)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.65843656,
+                                    0.5880859,
+                                    0.18862706,
+                                    0.856398,
+                                    0.18029327,
+                                    0.94851926)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.3841634,
+                                    0.25138793,
+                                    0.96746644,
+                                    0.77048045,
+                                    0.44685196,
+                                    0.19813854)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.65982267,
+                                    0.23024125,
+                                    0.13598434,
+                                    0.60144265,
+                                    0.57848927,
+                                    0.85623564)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.35764189,
+                                    0.47623815,
+                                    0.5459232,
+                                    0.79508298,
+                                    0.14462443,
+                                    0.01802919)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.38532153,
+                                    0.90614554,
+                                    0.86629571,
+                                    0.13988735,
+                                    0.32062385,
+                                    0.00179492)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.2142368,
+                                    0.28306022,
+                                    0.59481646,
+                                    0.42567028,
+                                    0.52207663,
+                                    0.78082401)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.20788283,
+                                    0.76861782,
+                                    0.59595468,
+                                    0.62103642,
+                                    0.17781246,
+                                    0.77655345)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.1751708,
+                                    0.4547537,
+                                    0.46187865,
+                                    0.79781199,
+                                    0.05104487,
+                                    0.42406092)));
+
+    private static final List<Row> SPARSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(3, Vectors.dense(6.0, 7.0, 0.0, 7.0, 6.0, 0.0, 0.0).toSparse()),
+                    Row.of(1, Vectors.dense(0.0, 9.0, 6.0, 0.0, 5.0, 9.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(0.0, 9.0, 3.0, 0.0, 5.0, 5.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(0.0, 9.0, 8.0, 5.0, 6.0, 4.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(8.0, 9.0, 6.0, 5.0, 4.0, 4.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(Double.NaN, 9.0, 6.0, 4.0, 0.0, 0.0, 0.0).toSparse()));
+
+    private static final Row EXPECTED_OUTPUT =
+            Row.of(
+                    Vectors.dense(
+                            0.64137831, 0.14830724, 0.69858474, 0.28038169, 0.86759161, 0.81608606),
+                    new long[] {19, 19, 19, 19, 19, 19},
+                    Vectors.dense(
+                            0.64110932, 1.98689258, 0.55499714, 1.40340562, 0.30881722, 0.3848595));
+
+    private static final List<Row> EXPECTED_FLATTENED_OUTPUT =
+            Arrays.asList(
+                    Row.of(0, 0.64137831, 19, 0.64110932),
+                    Row.of(1, 0.14830724, 19, 1.98689258),
+                    Row.of(2, 0.69858474, 19, 0.55499714),
+                    Row.of(3, 0.28038169, 19, 1.40340562),
+                    Row.of(4, 0.86759161, 19, 0.30881722),
+                    Row.of(5, 0.81608606, 19, 0.3848595));
+
+    private static final Row EXPECTED_OUTPUT_SPARSE =
+            Row.of(
+                    Vectors.dense(
+                            Double.NaN,

Review Comment:
   Why would this value be `0.71554175` in Spark, but `NaN` in Flink?



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;

Review Comment:
   The EPS in Spark is 1e-6.



##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;
+    private static final List<Row> DENSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.85956061,
+                                    0.1645695,
+                                    0.48347596,
+                                    0.92102727,
+                                    0.42855644,
+                                    0.05746009)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.92500743,
+                                    0.65760154,
+                                    0.13295284,
+                                    0.53344893,
+                                    0.8994776,
+                                    0.24836496)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.03017182,
+                                    0.07244715,
+                                    0.87416449,
+                                    0.55843035,
+                                    0.91604736,
+                                    0.63346045)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.28325261,
+                                    0.36536881,
+                                    0.09223386,
+                                    0.37251258,
+                                    0.34742278,
+                                    0.70517077)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.64850904,
+                                    0.04090877,
+                                    0.21173176,
+                                    0.00148992,
+                                    0.13897166,
+                                    0.21182539)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.02609493,
+                                    0.44608735,
+                                    0.23910531,
+                                    0.95449222,
+                                    0.90763182,
+                                    0.8624905)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.09158744,
+                                    0.97745235,
+                                    0.41150139,
+                                    0.45830467,
+                                    0.52590925,
+                                    0.29441554)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.97211594,
+                                    0.1814442,
+                                    0.30340642,
+                                    0.17445413,
+                                    0.52756958,
+                                    0.02069296)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.06354593,
+                                    0.63527231,
+                                    0.49620335,
+                                    0.0141264,
+                                    0.62722219,
+                                    0.63497507)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.10814149,
+                                    0.8296426,
+                                    0.51775217,
+                                    0.57068344,
+                                    0.54633305,
+                                    0.12714921)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.72731796,
+                                    0.94010124,
+                                    0.45007811,
+                                    0.87650674,
+                                    0.53735565,
+                                    0.49568415)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.41827208,
+                                    0.85100628,
+                                    0.38685271,
+                                    0.60689503,
+                                    0.21784097,
+                                    0.91294433)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.65843656,
+                                    0.5880859,
+                                    0.18862706,
+                                    0.856398,
+                                    0.18029327,
+                                    0.94851926)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.3841634,
+                                    0.25138793,
+                                    0.96746644,
+                                    0.77048045,
+                                    0.44685196,
+                                    0.19813854)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.65982267,
+                                    0.23024125,
+                                    0.13598434,
+                                    0.60144265,
+                                    0.57848927,
+                                    0.85623564)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.35764189,
+                                    0.47623815,
+                                    0.5459232,
+                                    0.79508298,
+                                    0.14462443,
+                                    0.01802919)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.38532153,
+                                    0.90614554,
+                                    0.86629571,
+                                    0.13988735,
+                                    0.32062385,
+                                    0.00179492)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.2142368,
+                                    0.28306022,
+                                    0.59481646,
+                                    0.42567028,
+                                    0.52207663,
+                                    0.78082401)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.20788283,
+                                    0.76861782,
+                                    0.59595468,
+                                    0.62103642,
+                                    0.17781246,
+                                    0.77655345)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.1751708,
+                                    0.4547537,
+                                    0.46187865,
+                                    0.79781199,
+                                    0.05104487,
+                                    0.42406092)));
+
+    private static final List<Row> SPARSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(3, Vectors.dense(6.0, 7.0, 0.0, 7.0, 6.0, 0.0, 0.0).toSparse()),
+                    Row.of(1, Vectors.dense(0.0, 9.0, 6.0, 0.0, 5.0, 9.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(0.0, 9.0, 3.0, 0.0, 5.0, 5.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(0.0, 9.0, 8.0, 5.0, 6.0, 4.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(8.0, 9.0, 6.0, 5.0, 4.0, 4.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(Double.NaN, 9.0, 6.0, 4.0, 0.0, 0.0, 0.0).toSparse()));
+
+    private static final Row EXPECTED_OUTPUT =
+            Row.of(
+                    Vectors.dense(
+                            0.64137831, 0.14830724, 0.69858474, 0.28038169, 0.86759161, 0.81608606),
+                    new long[] {19, 19, 19, 19, 19, 19},
+                    Vectors.dense(
+                            0.64110932, 1.98689258, 0.55499714, 1.40340562, 0.30881722, 0.3848595));
+
+    private static final List<Row> EXPECTED_FLATTENED_OUTPUT =
+            Arrays.asList(
+                    Row.of(0, 0.64137831, 19, 0.64110932),
+                    Row.of(1, 0.14830724, 19, 1.98689258),
+                    Row.of(2, 0.69858474, 19, 0.55499714),
+                    Row.of(3, 0.28038169, 19, 1.40340562),
+                    Row.of(4, 0.86759161, 19, 0.30881722),
+                    Row.of(5, 0.81608606, 19, 0.3848595));
+
+    private static final Row EXPECTED_OUTPUT_SPARSE =
+            Row.of(
+                    Vectors.dense(
+                            Double.NaN,
+                            0.71554175,
+                            0.34278574,
+                            0.45824059,
+                            0.84633632,
+                            0.15673368,
+                            Double.NaN),
+                    new long[] {5, 5, 5, 5, 5, 5, 5},
+                    Vectors.dense(
+                            Double.NaN, 0.375, 1.5625, 1.02364865, 0.17647059, 3.66, Double.NaN));
+
+    private static final List<Row> EXPECTED_FLATTENED_OUTPUT_SPARSE =
+            Arrays.asList(
+                    Row.of(0, Double.NaN, 5, Double.NaN),
+                    Row.of(1, 0.71554175, 5, 0.375),
+                    Row.of(2, 0.34278574, 5, 1.5625),
+                    Row.of(3, 0.45824059, 5, 1.02364865),
+                    Row.of(4, 0.84633632, 5, 0.17647059),
+                    Row.of(5, 0.15673368, 5, 3.66),
+                    Row.of(6, Double.NaN, 5, Double.NaN));
+
+    @Before
+    public void before() {
+        Configuration config = new Configuration();
+        config.set(ExecutionCheckpointingOptions.ENABLE_CHECKPOINTS_AFTER_TASKS_FINISH, true);
+        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(config);
+        env.setParallelism(4);
+        env.enableCheckpointing(100);
+        env.setRestartStrategy(RestartStrategies.noRestart());
+        env.getConfig().enableObjectReuse();
+        tEnv = StreamTableEnvironment.create(env);
+        denseInputTable =
+                tEnv.fromDataStream(env.fromCollection(DENSE_INPUT_DATA)).as("label", "features");
+        sparseInputTable =
+                tEnv.fromDataStream(env.fromCollection(SPARSE_INPUT_DATA)).as("label", "features");
+    }
+
+    private static void verifyFlattenTransformationResult(Table output, List<Row> expected)
+            throws Exception {
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) output).getTableEnvironment();
+        DataStream<Row> outputDataStream = tEnv.toDataStream(output);
+        List<Row> results = IteratorUtils.toList(outputDataStream.executeAndCollect());
+        assertEquals(expected.size(), results.size());
+
+        results.sort(Comparator.comparing(r -> String.valueOf(r.getField(0))));
+        expected.sort(Comparator.comparing(r -> String.valueOf(r.getField(0))));
+
+        for (int i = 0; i < expected.size(); i++) {
+            assertEquals(expected.get(i).getArity(), results.get(i).getArity());
+            for (int j = 0; j < expected.get(i).getArity(); j++) {
+                assertEquals(
+                        Double.valueOf(expected.get(i).getField(j).toString()),
+                        Double.valueOf(results.get(i).getField(j).toString()),
+                        EPS);
+            }
+        }
+    }
+
+    private static void verifyTransformationResult(Table output, Row expected) throws Exception {
+        StreamTableEnvironment tEnv =
+                (StreamTableEnvironment) ((TableImpl) output).getTableEnvironment();
+        DataStream<Row> outputDataStream = tEnv.toDataStream(output);
+        List<Row> results = IteratorUtils.toList(outputDataStream.executeAndCollect());
+        assertEquals(1, results.size());
+
+        Row result = results.get(0);
+        assertEquals(3, result.getArity());
+        compareVector((Vector) expected.getField(0), (Vector) result.getField(0));
+        assertArrayEquals((long[]) expected.getField(1), (long[]) result.getField(1));
+        compareVector((Vector) expected.getField(2), (Vector) result.getField(2));
+    }
+
+    private static void compareVector(Vector first, Vector second) {

Review Comment:
   It might be enough to replace `compareVector(v1, v2)` with `assertArrayEquals(v1.toArray(), v2.toArray(), EPS)`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on PR #180:
URL: https://github.com/apache/flink-ml/pull/180#issuecomment-1328721713

   @yunfengzhou-hub Thanks for the review, all comments are resolved.
   @lindong28 Could you also take a look at this PR?


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] lindong28 commented on pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
lindong28 commented on PR #180:
URL: https://github.com/apache/flink-ml/pull/180#issuecomment-1329172772

   Thanks for the PR! And thanks @yunfengzhou-hub for the review. LGTM.


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031178423


##########
flink-ml-python/pyflink/ml/lib/tests/test_ml_lib_completeness.py:
##########
@@ -81,6 +83,9 @@ def module_name(self):
     def module(self):
         pass
 
+    def exclude_java_stage(self):

Review Comment:
   I don't think we need to add a comment to a test method that is not difficult to understand, but we can leave the description here for developers' reference.
   
   For those java stages that have no corresponding python implementation, developers can skip testing them by overriding this function and listing them in the format `package.class`, e.g. `anovatest.ANOVATest`.
   



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031162643


##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;
+    private static final List<Row> DENSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.85956061,
+                                    0.1645695,
+                                    0.48347596,
+                                    0.92102727,
+                                    0.42855644,
+                                    0.05746009)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.92500743,
+                                    0.65760154,
+                                    0.13295284,
+                                    0.53344893,
+                                    0.8994776,
+                                    0.24836496)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.03017182,
+                                    0.07244715,
+                                    0.87416449,
+                                    0.55843035,
+                                    0.91604736,
+                                    0.63346045)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.28325261,
+                                    0.36536881,
+                                    0.09223386,
+                                    0.37251258,
+                                    0.34742278,
+                                    0.70517077)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.64850904,
+                                    0.04090877,
+                                    0.21173176,
+                                    0.00148992,
+                                    0.13897166,
+                                    0.21182539)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.02609493,
+                                    0.44608735,
+                                    0.23910531,
+                                    0.95449222,
+                                    0.90763182,
+                                    0.8624905)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.09158744,
+                                    0.97745235,
+                                    0.41150139,
+                                    0.45830467,
+                                    0.52590925,
+                                    0.29441554)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.97211594,
+                                    0.1814442,
+                                    0.30340642,
+                                    0.17445413,
+                                    0.52756958,
+                                    0.02069296)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.06354593,
+                                    0.63527231,
+                                    0.49620335,
+                                    0.0141264,
+                                    0.62722219,
+                                    0.63497507)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.10814149,
+                                    0.8296426,
+                                    0.51775217,
+                                    0.57068344,
+                                    0.54633305,
+                                    0.12714921)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.72731796,
+                                    0.94010124,
+                                    0.45007811,
+                                    0.87650674,
+                                    0.53735565,
+                                    0.49568415)),
+                    Row.of(
+                            2,
+                            Vectors.dense(
+                                    0.41827208,
+                                    0.85100628,
+                                    0.38685271,
+                                    0.60689503,
+                                    0.21784097,
+                                    0.91294433)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.65843656,
+                                    0.5880859,
+                                    0.18862706,
+                                    0.856398,
+                                    0.18029327,
+                                    0.94851926)),
+                    Row.of(
+                            4,
+                            Vectors.dense(
+                                    0.3841634,
+                                    0.25138793,
+                                    0.96746644,
+                                    0.77048045,
+                                    0.44685196,
+                                    0.19813854)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.65982267,
+                                    0.23024125,
+                                    0.13598434,
+                                    0.60144265,
+                                    0.57848927,
+                                    0.85623564)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.35764189,
+                                    0.47623815,
+                                    0.5459232,
+                                    0.79508298,
+                                    0.14462443,
+                                    0.01802919)),
+                    Row.of(
+                            5,
+                            Vectors.dense(
+                                    0.38532153,
+                                    0.90614554,
+                                    0.86629571,
+                                    0.13988735,
+                                    0.32062385,
+                                    0.00179492)),
+                    Row.of(
+                            3,
+                            Vectors.dense(
+                                    0.2142368,
+                                    0.28306022,
+                                    0.59481646,
+                                    0.42567028,
+                                    0.52207663,
+                                    0.78082401)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.20788283,
+                                    0.76861782,
+                                    0.59595468,
+                                    0.62103642,
+                                    0.17781246,
+                                    0.77655345)),
+                    Row.of(
+                            1,
+                            Vectors.dense(
+                                    0.1751708,
+                                    0.4547537,
+                                    0.46187865,
+                                    0.79781199,
+                                    0.05104487,
+                                    0.42406092)));
+
+    private static final List<Row> SPARSE_INPUT_DATA =
+            Arrays.asList(
+                    Row.of(3, Vectors.dense(6.0, 7.0, 0.0, 7.0, 6.0, 0.0, 0.0).toSparse()),
+                    Row.of(1, Vectors.dense(0.0, 9.0, 6.0, 0.0, 5.0, 9.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(0.0, 9.0, 3.0, 0.0, 5.0, 5.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(0.0, 9.0, 8.0, 5.0, 6.0, 4.0, 0.0).toSparse()),
+                    Row.of(2, Vectors.dense(8.0, 9.0, 6.0, 5.0, 4.0, 4.0, 0.0).toSparse()),
+                    Row.of(3, Vectors.dense(Double.NaN, 9.0, 6.0, 4.0, 0.0, 0.0, 0.0).toSparse()));
+
+    private static final Row EXPECTED_OUTPUT =
+            Row.of(
+                    Vectors.dense(
+                            0.64137831, 0.14830724, 0.69858474, 0.28038169, 0.86759161, 0.81608606),
+                    new long[] {19, 19, 19, 19, 19, 19},
+                    Vectors.dense(
+                            0.64110932, 1.98689258, 0.55499714, 1.40340562, 0.30881722, 0.3848595));
+
+    private static final List<Row> EXPECTED_FLATTENED_OUTPUT =
+            Arrays.asList(
+                    Row.of(0, 0.64137831, 19, 0.64110932),
+                    Row.of(1, 0.14830724, 19, 1.98689258),
+                    Row.of(2, 0.69858474, 19, 0.55499714),
+                    Row.of(3, 0.28038169, 19, 1.40340562),
+                    Row.of(4, 0.86759161, 19, 0.30881722),
+                    Row.of(5, 0.81608606, 19, 0.3848595));
+
+    private static final Row EXPECTED_OUTPUT_SPARSE =
+            Row.of(
+                    Vectors.dense(
+                            Double.NaN,

Review Comment:
   Spark doesn't test features with `NaN`. If a feature contains `NaN`, the p-value and f-value are expected to be `NaN`.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] lindong28 merged pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
lindong28 merged PR #180:
URL: https://github.com/apache/flink-ml/pull/180


-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink-ml] jiangxin369 commented on a diff in pull request #180: [FLINK-30159] Add Transformer for ANOVATest

Posted by GitBox <gi...@apache.org>.
jiangxin369 commented on code in PR #180:
URL: https://github.com/apache/flink-ml/pull/180#discussion_r1031158177


##########
flink-ml-lib/src/test/java/org/apache/flink/ml/stats/ANOVATestTest.java:
##########
@@ -0,0 +1,411 @@
+/*
+ * 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.stats;
+
+import org.apache.flink.api.common.restartstrategy.RestartStrategies;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.ml.linalg.Vector;
+import org.apache.flink.ml.linalg.Vectors;
+import org.apache.flink.ml.stats.anovatest.ANOVATest;
+import org.apache.flink.ml.util.TestUtils;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.streaming.api.environment.ExecutionCheckpointingOptions;
+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.table.api.internal.TableImpl;
+import org.apache.flink.test.util.AbstractTestBase;
+import org.apache.flink.types.Row;
+
+import org.apache.commons.collections.IteratorUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.List;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/** Tests the {@link ANOVATest}. */
+public class ANOVATestTest extends AbstractTestBase {
+    @Rule public final TemporaryFolder tempFolder = new TemporaryFolder();
+    private StreamTableEnvironment tEnv;
+    private Table denseInputTable;
+    private Table sparseInputTable;
+
+    private static final double EPS = 1.0e-5;

Review Comment:
   I think it is enough to use `1.0e-5` in tests, and also to keep consistent with other tests.



-- 
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-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org