Github user MLnick commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11832#discussion_r56948423
  
    --- Diff: 
mllib/src/test/scala/org/apache/spark/ml/feature/HashingTFSuite.scala ---
    @@ -52,6 +52,27 @@ class HashingTFSuite extends SparkFunSuite with 
MLlibTestSparkContext with Defau
         assert(features ~== expected absTol 1e-14)
       }
     
    +  test("applying binary term freqs") {
    +    val df = sqlContext.createDataFrame(Seq(
    +      (0, "a a b c c c".split(" ").toSeq)
    +    )).toDF("id", "words")
    +    val n = 100
    +    val hashingTF = new HashingTF()
    +        .setInputCol("words")
    +        .setOutputCol("features")
    +        .setNumFeatures(n)
    +        .setBinary(true)
    +    val output = hashingTF.transform(df)
    +    val attrGroup = 
AttributeGroup.fromStructField(output.schema("features"))
    +    require(attrGroup.numAttributes === Some(n))
    +    val features = output.select("features").first().getAs[Vector](0)
    +    // Assume perfect hash on "a", "b", "c".
    +    def idx(any: Any): Int = Utils.nonNegativeMod(any.##, n)
    +    val expected = Vectors.sparse(n,
    +      Seq((idx("a"), 1.0), (idx("b"), 1.0), (idx("c"), 1.0)))
    +    assert(features ~== expected absTol 1e-14)
    +  }
    --- End diff --
    
    I think the idea is that you could test both normal mode and binary mode in 
the same test - though I personally like separate test cases as it is more 
obvious what went wrong when it fails. You can pare down this test though (see 
my other comments).
    
    I think the MLlib test is fine as is.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to