Skip to content

Instantly share code, notes, and snippets.

@retrospectacus
Forked from zeryx/streaming_knn.scala
Last active May 2, 2018 23:26
Show Gist options
  • Save retrospectacus/0ead737903757c12ea2d6b1a76dc19ee to your computer and use it in GitHub Desktop.
Save retrospectacus/0ead737903757c12ea2d6b1a76dc19ee to your computer and use it in GitHub Desktop.
val result: Stream[Task, Prediction] = specimenStream.flatMap((spec: Document) =>{
modelStream.fold(List.empty[TopN]) { case (topNVec, mod) =>
val res = calcDistance(spec, mod)
val newTopN = TopN(res.modelElm.label.get, res.distance)
(topNVec :+ newTopN).sortBy(res => res.confidence).take(nearest)
}.map(topNVec => Prediction(spec.text, topNVec.toList) )
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment