> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# aggregate_k_means

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/generated/aggregate_k_means.rs#L38-L53)
pub async fn [aggregate\_k\_means](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica/aggregate-k-means.md#method.aggregate_k_means)( \&self, table\_name: [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html), column\_names: [Vec](https://doc.rust-lang.org/1.98.1/alloc/vec/struct.Vec.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, k: [i32](https://doc.rust-lang.org/1.98.1/std/primitive.i32.html), tolerance: [f64](https://doc.rust-lang.org/1.98.1/std/primitive.f64.html), ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<[AggregateKMeansResponse](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansResponse.md), [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Run the k-means algorithm on a datasetThis endpoint runs the k-means algorithm - a heuristic algorithm that attempts to do k-means clustering. An ideal k-means clustering algorithm selects k points such that the sum of the mean squared distances of each member of the set to the nearest of the k points is minimized. The k-means algorithm however does not necessarily produce such an ideal cluster. It begins with a randomly selected set of k points and then refines the location of the points iteratively and settles to a local minimum. Various parameters and options are provided to control the heuristic search.NOTE: The Kinetica instance being accessed must be running a CUDA (GPU-based) build to service this request.

##### Arguments

<ul>
  <li>`table_name` - Name of the table on which the operation will be performed. Must be an existing table, in \[schema\_name.]table\_name format, using standard name resolution rules.</li>
  <li>`column_names` - List of column names on which the operation would be performed. If n columns are provided then each of the k result points will have n dimensions corresponding to the n columns.</li>
  <li>`k` - The number of mean points to be determined by the algorithm.</li>
  <li>`tolerance` - Stop iterating when the distances between successive points is less than the given tolerance.</li>
</ul>

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/generated/aggregate_k_means.rs#L83-L105)
pub async fn [aggregate\_k\_means\_with\_opts](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica/aggregate-k-means.md#method.aggregate_k_means_with_opts)( \&self, table\_name: [String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html), column\_names: [Vec](https://doc.rust-lang.org/1.98.1/alloc/vec/struct.Vec.html)\<[String](https://doc.rust-lang.org/1.98.1/alloc/string/struct.String.html)>, k: [i32](https://doc.rust-lang.org/1.98.1/std/primitive.i32.html), tolerance: [f64](https://doc.rust-lang.org/1.98.1/std/primitive.f64.html), options: [AggregateKMeansRequestOptions](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansRequestOptions.md), ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<[AggregateKMeansResponse](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansResponse.md), [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Run the k-means algorithm on a datasetThis endpoint runs the k-means algorithm - a heuristic algorithm that attempts to do k-means clustering. An ideal k-means clustering algorithm selects k points such that the sum of the mean squared distances of each member of the set to the nearest of the k points is minimized. The k-means algorithm however does not necessarily produce such an ideal cluster. It begins with a randomly selected set of k points and then refines the location of the points iteratively and settles to a local minimum. Various parameters and options are provided to control the heuristic search.NOTE: The Kinetica instance being accessed must be running a CUDA (GPU-based) build to service this request.

##### Arguments

<ul>
  <li>`table_name` - Name of the table on which the operation will be performed. Must be an existing table, in \[schema\_name.]table\_name format, using standard name resolution rules.</li>
  <li>`column_names` - List of column names on which the operation would be performed. If n columns are provided then each of the k result points will have n dimensions corresponding to the n columns.</li>
  <li>`k` - The number of mean points to be determined by the algorithm.</li>
  <li>`tolerance` - Stop iterating when the distances between successive points is less than the given tolerance.</li>
  <li>`options` - The optional parameters; any left unset take the server’s defaults.</li>
</ul>

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/generated/aggregate_k_means.rs#L108-L119)
pub async fn [aggregate\_k\_means\_raw](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica/aggregate-k-means.md#method.aggregate_k_means_raw)( \&self, request: &[AggregateKMeansRequest](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansRequest.md), ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<[AggregateKMeansResponse](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansResponse.md), [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Sends a pre-built [`AggregateKMeansRequest`](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansRequest) to the `/aggregate/kmeans` endpoint.

[Source](https://github.com/kineticadb/kinetica-api-rust/blob/master/crates/gpudb-api/src/generated/aggregate_k_means.rs#L123-L135)
pub async fn [aggregate\_k\_means\_from\_url](https://docs.kinetica.com/content/api/rust/gpudb/struct.Kinetica/aggregate-k-means.md#method.aggregate_k_means_from_url)( \&self, url: &[str](https://doc.rust-lang.org/1.98.1/std/primitive.str.html), request: &[AggregateKMeansRequest](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansRequest.md), ) -> [Result](https://doc.rust-lang.org/1.98.1/core/result/enum.Result.html)\<[AggregateKMeansResponse](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansResponse.md), [KineticaError](https://docs.kinetica.com/content/api/rust/errors/enum.KineticaError.md)>

Sends a pre-built [`AggregateKMeansRequest`](https://docs.kinetica.com/content/api/rust/generated/api/struct.AggregateKMeansRequest) to a specific worker URL, bypassing HA head-node selection. Used for multi-head access.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.