zhengruifeng commented on a change in pull request #26415: [SPARK-18409][ML] 
LSH approxNearestNeighbors should use approxQuantile instead of sort
URL: https://github.com/apache/spark/pull/26415#discussion_r348897431
 
 

 ##########
 File path: mllib/src/main/scala/org/apache/spark/ml/feature/LSH.scala
 ##########
 @@ -112,7 +112,9 @@ private[ml] abstract class LSHModel[T <: LSHModel[T]]
       numNearestNeighbors: Int,
       singleProbe: Boolean,
       distCol: String): Dataset[_] = {
-    require(numNearestNeighbors > 0, "The number of nearest neighbors cannot 
be less than 1")
+    val count = dataset.count()
 
 Review comment:
   According to the 
[doc](https://github.com/apache/spark/blob/56a65b971d4f1b43c37a5664a3a4e2e4fcad1c14/mllib/src/main/scala/org/apache/spark/ml/feature/LSH.scala#L175)
 
   "@param numNearestNeighbors The maximum number of nearest neighbors."
   It imply that the output should not contain exact `numNearestNeighbors` 
items.
   
   1, if we do not require `numNearestNeighbors <= count`, then if 
`singleProbe` is true, this `count` job can be avoided.
   2, if we found that `numNearestNeighbors <= count`, we can directly return 
`modelDatasetWithDist`.
   

----------------------------------------------------------------
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]

Reply via email to