Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
K

kmeans-clusterer

> 编程语言
Open source

k-means clustering in Ruby

99 stars0 likes3 views
WebsiteGitHub

About

k-means clustering in Ruby

KMeansClusterer

k-means clustering in Ruby. Uses NArray under the hood for fast calculations.

Jump to the examples directory to see this in action.

Features

  • Runs multiple clustering attempts to find optimal solution (single runs are susceptible to falling into non-optimal local minima)
  • Initializes centroids via k-means++ algorithm, for faster convergence
  • Calculates silhouette score for evaluation
  • Option to scale data before clustering, so that output isn't biased by different feature scales
  • Works with high-dimensional data

Install

gem install kmeans-clusterer

Usage

Simple example:

…

Output of simple example:

0. New York, Baltimore, Washington DC [39.63, -75.89]
1. Los Angeles, Portland, Las Vegas [38.56, -118.7]

Closest cluster to Chicago: 0

Silhouette score: 0.91

Options

The following options can be passed in to KMeansClusterer.run:

option default description
:labels nil optional array of Ruby objects to collate with data array
:runs 10 number of times to run kmeans
:log false print stats after each run
:init :kmpp algorithm for picking initial cluster centroids. Accepts :kmpp, :random, or an array of k centroids
:scale_data false scales features before clustering using formula (data - mean) / std
:float_precision :double float precision to use. :double or :single
:max_iter 300 max iterations per run

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rubyclusteringkmeans-clusteringrubyrubyml

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言