srowen commented on a change in pull request #24764: [SPARK-18570][ML][R]
RFormula support * and ^ operators
URL: https://github.com/apache/spark/pull/24764#discussion_r289642804
##########
File path:
mllib/src/test/scala/org/apache/spark/ml/feature/RFormulaParserSuite.scala
##########
@@ -90,12 +90,48 @@ class RFormulaParserSuite extends SparkFunSuite {
test("parse interactions") {
checkParse("y ~ a:b", "y", Seq("a:b"))
+ checkParse("y ~ a:b + b:a", "y", Seq("a:b"))
checkParse("y ~ ._a:._x", "y", Seq("._a:._x"))
checkParse("y ~ foo:bar", "y", Seq("foo:bar"))
checkParse("y ~ a : b : c", "y", Seq("a:b:c"))
checkParse("y ~ q + a:b:c + b:c + c:d + z", "y", Seq("q", "a:b:c", "b:c",
"c:d", "z"))
}
+ test("parse factor cross") {
+ checkParse("y ~ a*b", "y", Seq("a", "b", "a:b"))
+ checkParse("y ~ a*b + b*a", "y", Seq("a", "b", "a:b"))
+ checkParse("y ~ ._a*._x", "y", Seq("._a", "._x", "._a:._x"))
+ checkParse("y ~ foo*bar", "y", Seq("foo", "bar", "foo:bar"))
+ checkParse("y ~ a * b * c", "y", Seq("a", "b", "a:b", "c", "a:c", "b:c",
"a:b:c"))
+ }
+
+ test("interaction distributive") {
+ checkParse("y ~ (a + b):c", "y", Seq("a:c", "b:c"))
+ checkParse("y ~ c:(a + b)", "y", Seq("c:a", "c:b"))
+ }
+
+ test("factor cross distributive") {
+ checkParse("y ~ (a + b)*c", "y", Seq("a", "b", "c", "a:c", "b:c"))
+ checkParse("y ~ c*(a + b)", "y", Seq("c", "a", "b", "c:a", "c:b"))
Review comment:
I don't think this is a problem, just curious: the order of terms in an
interaction doesn't matter, but I wonder if we handle the case that say a:c and
c:a are generated, and only return a:c? might be worth one test case somewhere.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]