KMEANS.CENTERS OpenBI
The centres of the k-means clusters, with their sizes and scatter.
Group: Many variables at once. OpenBI’s own: DAX has no function of this name.
Syntax
KMEANS.CENTERS ( <table>, <k>, <name>, <expression> [, <name>, <expression>] … )
| Parameter | Type | Description |
|---|---|---|
table | Table | The rows to cluster. |
k | Whole number | How many clusters: 1 to 100. |
name | Text repeatable | A variable's name, a text in quotes; one or more variables. |
expression | Expression repeatable, evaluated for each row | That variable's number for each row. |
Returns
Table. One row per cluster: its number (Cluster) and Size, then a column for each variable, named after it, with the cluster's average in that variable's own units, then Within SS, Between share and Silhouette.
Remarks
- The clusters are those
KMEANSgives for the same table, k and variables, numbered the same way. - Within SS is the cluster's scatter about its centre, in standardised units. Between share is the part of all the variation that the clustering explains (between SS over total SS, as R's kmeans prints it); it is the same on every row.
- Silhouette is the mean silhouette of the cluster's rows.
- Every variable is first put on one scale: how many standard deviations each row lies above or below that variable's mean. Liters and kroner then weigh alike, and a change of units changes nothing.
- A row where any variable is blank is left out. A variable must be a number on every row (text is an error, even text that reads as a number), and one that is the same on every row is an error too.
Compared with DAX
An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.
Examples
The two kinds of shop, described
EVALUATE
VAR Shops =
DATATABLE (
"Shop", STRING, "Liters", INTEGER, "Visits", INTEGER,
{
{ "A", 100, 10 }, { "B", 110, 12 }, { "C", 95, 9 },
{ "D", 400, 30 }, { "E", 420, 33 }, { "F", 390, 28 }
}
)
RETURN
KMEANS.CENTERS ( Shops, 2, "Liters", [Liters], "Visits", [Visits] )
| Cluster | Size | Liters | Visits | Within SS | Between share | Silhouette |
|---|---|---|---|---|---|---|
| 1 | 3 | 101.666666666667 | 10.3333333333333 | 0.0420521660537605 | 0.983833528204221 | 0.925368511782275 |
| 2 | 3 | 403.333333333333 | 30.3333333333333 | 0.119612551904027 | 0.983833528204221 | 0.873847813396297 |
The centres of three delivery areas
EVALUATE
KMEANS.CENTERS ( Places, 3, "Lat", Places[Lat], "Lon", Places[Lon] )
| Cluster | Size | Lat | Lon | Within SS | Between share | Silhouette |
|---|---|---|---|---|---|---|
| 1 | 7 | 59.9143647142857 | 10.7799288571429 | 6.63478989668715 | 0.668719214693785 | 0.38928429657122 |
| 2 | 6 | 59.9389908333333 | 10.757777 | 2.5113042378147 | 0.668719214693785 | 0.484500423495288 |
| 3 | 3 | 59.92207 | 10.7007786666667 | 0.792329424684598 | 0.668719214693785 | 0.53240850146802 |