> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/cuvs/llms.txt.
> For full documentation content, see https://docs.nvidia.com/cuvs/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/cuvs/_mcp/server.

# Silhouette Score

_Source header: `cuvs/stats/silhouette_score.hpp`_

## Silhouette Score

<a id="stats-silhouette-score"></a>
### stats::silhouette_score

main function that returns the average silhouette score for a given set of data and its

```cpp
float silhouette_score(
raft::resources const& handle,
raft::device_matrix_view<const float, int64_t, raft::row_major> X_in,
raft::device_vector_view<const int, int64_t> labels,
std::optional<raft::device_vector_view<float, int64_t>> silhouette_score_per_sample,
int64_t n_unique_labels,
cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded);
```

clusterings nRows) for every sample (length: nRows)

**Parameters**

| Name | Direction | Type | Description |
| --- | --- | --- | --- |
| `handle` | in | `raft::resources const&` | : raft handle for managing expensive resources |
| `X_in` | in | `raft::device_matrix_view<const float, int64_t, raft::row_major>` | : input matrix Data in row-major format (nRows x nCols) |
| `labels` | in | `raft::device_vector_view<const int, int64_t>` | : the pointer to the array containing labels for every data sample (length: |
| `silhouette_score_per_sample` | out | `std::optional<raft::device_vector_view<float, int64_t>>` | : optional array populated with the silhouette score |
| `n_unique_labels` | in | `int64_t` | : number of unique labels in the labels array |
| `metric` | in | [`cuvs::distance::DistanceType`](/api-reference/cpp-api-distance-distance#distance-distancetype) | : Distance metric to use. Euclidean (L2) is used by default Default: `cuvs::distance::DistanceType::L2Unexpanded`. |

**Returns**

`float`

: The silhouette score.

<a id="stats-silhouette-score-batched"></a>
### stats::silhouette_score_batched

function that returns the average silhouette score for a given set of data and its

```cpp
float silhouette_score_batched(
raft::resources const& handle,
raft::device_matrix_view<const float, int64_t, raft::row_major> X,
raft::device_vector_view<const int, int64_t> labels,
std::optional<raft::device_vector_view<float, int64_t>> silhouette_score_per_sample,
int64_t n_unique_labels,
int64_t batch_size,
cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded);
```

clusterings nRows) for every sample (length: nRows) the calculations

**Parameters**

| Name | Direction | Type | Description |
| --- | --- | --- | --- |
| `handle` | in | `raft::resources const&` | : raft handle for managing expensive resources |
| `X` | in | `raft::device_matrix_view<const float, int64_t, raft::row_major>` | : input matrix Data in row-major format (nRows x nCols) |
| `labels` | in | `raft::device_vector_view<const int, int64_t>` | : the pointer to the array containing labels for every data sample (length: |
| `silhouette_score_per_sample` | out | `std::optional<raft::device_vector_view<float, int64_t>>` | : optional array populated with the silhouette score |
| `n_unique_labels` | in | `int64_t` | : number of unique labels in the labels array |
| `batch_size` | in | `int64_t` | : number of samples per batch |
| `metric` | in | [`cuvs::distance::DistanceType`](/api-reference/cpp-api-distance-distance#distance-distancetype) | : the numerical value that maps to the type of distance metric to be used in Default: `cuvs::distance::DistanceType::L2Unexpanded`. |

**Returns**

`float`

: The silhouette score.

**Additional overload:** `stats::silhouette_score`

main function that returns the average silhouette score for a given set of data and its

```cpp
double silhouette_score(
raft::resources const& handle,
raft::device_matrix_view<const double, int64_t, raft::row_major> X_in,
raft::device_vector_view<const int, int64_t> labels,
std::optional<raft::device_vector_view<double, int64_t>> silhouette_score_per_sample,
int64_t n_unique_labels,
cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded);
```

clusterings nRows) for every sample (length: nRows) the calculations

**Parameters**

| Name | Direction | Type | Description |
| --- | --- | --- | --- |
| `handle` | in | `raft::resources const&` | : raft handle for managing expensive resources |
| `X_in` | in | `raft::device_matrix_view<const double, int64_t, raft::row_major>` | : input matrix Data in row-major format (nRows x nCols) |
| `labels` | in | `raft::device_vector_view<const int, int64_t>` | : the pointer to the array containing labels for every data sample (length: |
| `silhouette_score_per_sample` | out | `std::optional<raft::device_vector_view<double, int64_t>>` | : optional array populated with the silhouette score |
| `n_unique_labels` | in | `int64_t` | : number of unique labels in the labels array |
| `metric` | in | [`cuvs::distance::DistanceType`](/api-reference/cpp-api-distance-distance#distance-distancetype) | : the numerical value that maps to the type of distance metric to be used in Default: `cuvs::distance::DistanceType::L2Unexpanded`. |

**Returns**

`double`

: The silhouette score.

**Additional overload:** `stats::silhouette_score_batched`

function that returns the average silhouette score for a given set of data and its

```cpp
double silhouette_score_batched(
raft::resources const& handle,
raft::device_matrix_view<const double, int64_t, raft::row_major> X,
raft::device_vector_view<const int, int64_t> labels,
std::optional<raft::device_vector_view<double, int64_t>> silhouette_score_per_sample,
int64_t n_unique_labels,
int64_t batch_size,
cuvs::distance::DistanceType metric = cuvs::distance::DistanceType::L2Unexpanded);
```

clusterings nRows) for every sample (length: nRows) the calculations

**Parameters**

| Name | Direction | Type | Description |
| --- | --- | --- | --- |
| `handle` | in | `raft::resources const&` | : raft handle for managing expensive resources |
| `X` | in | `raft::device_matrix_view<const double, int64_t, raft::row_major>` | : input matrix Data in row-major format (nRows x nCols) |
| `labels` | in | `raft::device_vector_view<const int, int64_t>` | : the pointer to the array containing labels for every data sample (length: |
| `silhouette_score_per_sample` | out | `std::optional<raft::device_vector_view<double, int64_t>>` | : optional array populated with the silhouette score |
| `n_unique_labels` | in | `int64_t` | : number of unique labels in the labels array |
| `batch_size` | in | `int64_t` | : number of samples per batch |
| `metric` | in | [`cuvs::distance::DistanceType`](/api-reference/cpp-api-distance-distance#distance-distancetype) | : the numerical value that maps to the type of distance metric to be used in Default: `cuvs::distance::DistanceType::L2Unexpanded`. |

**Returns**

`double`

: The silhouette score.