Skip to content

SercanKaraoglu/kmeans

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kmeans

kmeans scala implementation in 13 lines

  @tailrec
      def _kmeans(means: ParArray[Specy]): ParArray[(Specy, ParVector[Specy])] = {
        val newMeans: ParArray[(Specy, ParVector[Specy])] =
          means.map(mean => {
            _species.groupBy(p => means.minBy(_.distance(p))).get(mean) match {
              case Some(c) => (c.sum / c.length, c)
              case None => (mean, ParVector(mean))
            }
          })
        val converged = (means zip newMeans.map(_._1)).forall {
          case (oldMean, newMean) => oldMean.distance(newMean) <= eta
        }
        if (!converged) _kmeans(newMeans.map(_._1)) else newMeans
      }

About

kmeans scala implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages