KMeans finds clusters based on the K-means++ algorithm. It assigns a number to every cluster.
KMeans consists of two steps, as in Linear Regression. The first step is training a model, meaning finding the centroids of the clusters. Second, cluster the values by the model. Our KMeans implementation is very flexible and allows the user to specify on which data the algorithm should train, and which data it should cluster.
There is also a simple KMeans operator, which just expects the number of clusters.
Simple Kmeans. It creates K clusters based on all other inputs in the query:
- k: Number of clusters.
- TRAIN_KM: Finds K centroids in the cluster. Authorization objects are still respected.
- TRAIN_FILTERED_KM: Finds K centroids in the filtered data.
- EXCLUDED: Here you can optionally define dimensions which influence the aggregations used for model training, but are not itself included in the training.
- INPUT: One or more columns, which is used to train the model.
- k: Number of clusters.
- CLUSTER: One or more columns, which are clustered based on the trained centroids.
All columns in TRAIN_KM have to be joinable. The columns in CLUSTER do not have to be joinable with the columns in TRAIN_KM.
The input of the model training is regarded as an independent sub query. This means if an aggregation is used, it is independent of the dimensions defined in the rest of the query. This also means that the columns within TRAIN_KM have to be joinable, but not with the columns used in the rest of the query.
- If a row contains a NULL value, the value is ignored and does not affect the model.
- If a
CLUSTERrow contains a NULL value, the result for that row will be NULL.
If rows of a column are filtered, it does not affect the linear model, as long as the kmeans model is not trained on aggregation results. This means independent of filters and selections, the underlying model stays the same. If you want to restrict the input data of a model you can use a CASE WHEN statement and map the values you want to be ignored to null. If a model is trained on results of an aggregation it still changes with the filtering because the result of the aggregation is affected by the filtering.
If a filter or selection changes, the model is retrained and the resulting function adopts to the new of view of data. This has a serious performance impact.
KMeans finds clusters based on the K-means++ algorithm. It assigns a number to every cluster. K-means is not a stable algorithm, so you can get different results when executing the algorithm multiple times. Therefore you must not rely that clusters stay the same.