The KMeansClustering package provides an implementation of the K-means clustering algorithm, allowing for the partitioning of a dataset into k clusters. It includes customizable initialization methods for cluster centers and supports different K-means algorithms.
You can install KMeansClustering.jl
by adding it directly from our GitHub repository. Here are the steps:
Open Julia's REPL (the Julia command-line interface).
Press ]
to enter Pkg mode (the prompt should change to pkg>
).
Run the following command to add KMeansClustering.jl
:
pkg> add https://github.com/idil-tub/KMeansClustering.jl.git
using KMeansClustering
# Generate some sample data
data = rand(2, 100) # 100 data points in 2 dimensions
# Convert data to an AbstractVector of Vector{Float64}
data_vec = [data[:, i] for i in 1:size(data, 2)]
# Perform k-means clustering
k = 3
max_iter = 100
tol = 0.0001
clusters = KMeans(data_vec, k; max_iter=max_iter, tol=tol)
# Print cluster centers and their members
for (center, members) in clusters
println("Cluster center: ", center)
println("Members: ", members)
end