APPLY_KMEANS
Assigns each row of an input table or view to a cluster center from an already-existing k-means model.
Important: Before using a machine learning function, be aware that all the ongoing transactions might be committed.
Syntax
APPLY_KMEANS ( col1, col2, ..., coln USING PARAMETERS model_name='name_of_model_created_previously' [,match_by_pos = 'method'] )
Arguments
col1, col2, ..., coln |
The columns to use from the input table or view. |
Parameters
model_name='name_of_kmeans_model_created_previously' |
The name of the k-means model. |
match_by_pos= 'method' |
(Optional) Valid Values:
|
Privileges
To use APPLY_KMEANS, you must either be the dbadmin, owner of the model or have USAGE privileges. There are no privileges needed on the function itself.
See GRANT (Schema) and GRANT (Table).
Examples
The following example shows how you can use the APPLY_KMEANS function on an input table. Note that you can mix column names and constants:
=> SELECT id, APPLY_KMEANS(Sepal_Length, 2.2, 1.3, Petal_Width USING PARAMETERS model_name='myKmeansModel', match_by_pos='true') FROM iris2; id | APPLY_KMEANS -----+-------------- 5 | 1 10 | 1 14 | 1 15 | 1 21 | 1 22 | 1 24 | 1 25 | 1 32 | 1 33 | 1 34 | 1 35 | 1 38 | 1 39 | 1 42 | 1 . . . (60 rows)
The following example shows how you can use the APPLY_KMEANS function on an input table, using the match_by_pos
parameter. Note that providing constants instead of column names works with this parameter:
=> SELECT id, APPLY_KMEANS(0,0,0,0 USING PARAMETERS model_name='myKmeansModel', match_by_pos='true') FROM iris ORDER BY id; id | APPLY_KMEANS -----+-------------- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 1 6 | 1 7 | 1 8 | 1 9 | 1 10 | 1 11 | 1 12 | 1 13 | 1 14 | 1 15 | 1 . . . (150 rows)