<s>
In	O
statistics	O
,	O
k-medians	B-Algorithm
clustering	I-Algorithm
is	O
a	O
cluster	B-Algorithm
analysis	I-Algorithm
algorithm	O
.	O
</s>
<s>
It	O
is	O
a	O
variation	O
of	O
k-means	B-Algorithm
clustering	I-Algorithm
where	O
instead	O
of	O
calculating	O
the	O
mean	O
for	O
each	O
cluster	O
to	O
determine	O
its	O
centroid	O
,	O
one	O
instead	O
calculates	O
the	O
median	O
.	O
</s>
<s>
This	O
has	O
the	O
effect	O
of	O
minimizing	O
error	O
over	O
all	O
clusters	O
with	O
respect	O
to	O
the	O
1-norm	O
distance	O
metric	O
,	O
as	O
opposed	O
to	O
the	O
squared	O
2-norm	O
distance	O
metric	O
(	O
which	O
k-means	B-Algorithm
does	O
.	O
)	O
</s>
<s>
This	O
relates	O
directly	O
to	O
the	O
k-median	B-Algorithm
problem	I-Algorithm
with	O
respect	O
to	O
the	O
1-norm	O
,	O
which	O
is	O
the	O
problem	O
of	O
finding	O
k	O
centers	O
such	O
that	O
the	O
clusters	O
formed	O
by	O
them	O
are	O
the	O
most	O
compact	O
.	O
</s>
<s>
The	O
criterion	O
function	O
formulated	O
in	O
this	O
way	O
is	O
sometimes	O
a	O
better	O
criterion	O
than	O
that	O
used	O
in	O
the	O
k-means	B-Algorithm
clustering	I-Algorithm
algorithm	I-Algorithm
,	O
in	O
which	O
the	O
sum	O
of	O
the	O
squared	O
distances	O
is	O
used	O
.	O
</s>
<s>
The	O
proposed	O
algorithm	O
uses	O
Lloyd-style	O
iteration	O
which	O
alternates	O
between	O
an	O
expectation	O
(	O
E	O
)	O
and	O
maximization	O
(	O
M	O
)	O
step	O
,	O
making	O
this	O
an	O
expectation	B-Algorithm
–	I-Algorithm
maximization	I-Algorithm
algorithm	I-Algorithm
.	O
</s>
<s>
The	O
median	O
is	O
computed	O
in	O
each	O
single	O
dimension	O
in	O
the	O
Manhattan-distance	O
formulation	O
of	O
the	O
k-medians	B-Algorithm
problem	O
,	O
so	O
the	O
individual	O
attributes	O
will	O
come	O
from	O
the	O
dataset	O
(	O
or	O
be	O
an	O
average	O
of	O
two	O
values	O
from	O
the	O
dataset	O
)	O
.	O
</s>
<s>
This	O
algorithm	O
is	O
often	O
confused	O
with	O
the	O
k-medoids	B-Algorithm
algorithm	O
.	O
</s>
<s>
However	O
,	O
a	O
medoid	B-Algorithm
has	O
to	O
be	O
an	O
actual	O
instance	O
from	O
the	O
dataset	O
,	O
while	O
for	O
the	O
multivariate	O
Manhattan-distance	O
median	O
this	O
only	O
holds	O
for	O
single	O
attribute	O
values	O
.	O
</s>
<s>
For	O
example	O
,	O
given	O
the	O
vectors	O
(	O
0	O
,	O
1	O
)	O
,	O
(	O
1	O
,	O
0	O
)	O
and	O
(	O
2	O
,	O
2	O
)	O
,	O
the	O
Manhattan-distance	O
median	O
is	O
(	O
1	O
,	O
1	O
)	O
,	O
which	O
does	O
not	O
exist	O
in	O
the	O
original	O
data	O
,	O
and	O
thus	O
cannot	O
be	O
a	O
medoid	B-Algorithm
.	O
</s>
<s>
ELKI	B-Language
includes	O
various	O
k-means	B-Algorithm
variants	O
,	O
including	O
k-medians	B-Algorithm
.	O
</s>
<s>
GNU	B-Language
R	I-Language
includes	O
k-medians	B-Algorithm
in	O
the	O
"	O
flexclust	O
"	O
package	O
.	O
</s>
