emel/ml/k_means
Aims to partition n observations into k clusters in which each observation belongs to the cluster with the nearest mean.
Functions
pub fn classifier(data: List(List(Float)), k: Int) -> fn(
List(Float),
) -> Int
Returns the function that classifies a point by identifying the index of the cluster it belongs to.
Points = [
[0.0, 0.0],
[4.0, 4.0],
[9.0, 9.0],
[4.3, 4.3],
[9.9, 9.9],
[4.4, 4.4],
[0.1, 0.1],
],
K = 3,
F = emel@ml@k_means:clusters(Points, K),
F([4.7, 4.7]).
% 1
pub fn clusters(points: List(List(Float)), k: Int) -> List(
List(List(Float)),
)
The points
get partitioned into k
clusters in which each point belongs to the cluster with the nearest mean.
Points = [
[0.0, 0.0],
[4.0, 4.0],
[9.0, 9.0],
[4.3, 4.3],
[9.9, 9.9],
[4.4, 4.4],
[0.1, 0.1],
],
K = 3,
emel@ml@k_means:clusters(Points, K).
% [
% [[0.1, 0.1], [0.0, 0.0]],
% [[4.0, 4.0], [4.3, 4.3], [4.4, 4.4]],
% [[9.9, 9.9], [9.0, 9.0]],
% ]