> For the complete documentation index, see [llms.txt](https://docs.seldon.ai/alibi-explain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.seldon.ai/alibi-explain/api-reference/confidence/trustscore.md).

# alibi.confidence.trustscore

## Constants

### `logger`

```python
logger: logging.Logger = <Logger alibi.confidence.trustscore (WARNING)>
```

Instances of the Logger class represent a single logging channel. A "logging channel" indicates an area of an application. Exactly how an "area" is defined is up to the application developer. Since an application can have any number of areas, logging channels are identified by a unique string. Application areas can be nested (e.g. an area of "input processing" might include sub-areas "read CSV files", "read XLS files" and "read Gnumeric files"). To cater for this natural nesting, channel names are organized into a namespace hierarchy where levels are separated by periods, much like the Java or Python package namespace. So in the instance given above, channel names might be "input" for the upper level, and "input.csv", "input.xls" and "input.gnu" for the sub-levels. There is no arbitrary limit to the depth of nesting.

## `TrustScore`

### Constructor

```python
TrustScore(self, k_filter: int = 10, alpha: float = 0.0, filter_type: Optional[str] = None, leaf_size: int = 40, metric: str = 'euclidean', dist_filter_type: str = 'point') -> None
```

| Name               | Type            | Default       | Description                                                                                                                                                                            |
| ------------------ | --------------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `k_filter`         | `int`           | `10`          | Number of neighbors used during either kNN distance or probability filtering.                                                                                                          |
| `alpha`            | `float`         | `0.0`         | Fraction of instances to filter out to reduce impact of outliers.                                                                                                                      |
| `filter_type`      | `Optional[str]` | `None`        | Filter method: `'distance_knn'`                                                                                                                                                        |
| `leaf_size`        | `int`           | `40`          | Number of points at which to switch to brute-force. Affects speed and memory required to build trees. Memory to store the tree scales with `n_samples / leaf_size`.                    |
| `metric`           | `str`           | `'euclidean'` | Distance metric used for the tree. See `sklearn` DistanceMetric class for a list of available metrics.                                                                                 |
| `dist_filter_type` | `str`           | `'point'`     | Use either the distance to the k-nearest point (`dist_filter_type = 'point'`) or the average distance from the first to the k-nearest point in the data (`dist_filter_type = 'mean'`). |

### Methods

#### `filter_by_distance_knn`

```python
filter_by_distance_knn(X: numpy.ndarray) -> numpy.ndarray
```

| Name | Type            | Default | Description |
| ---- | --------------- | ------- | ----------- |
| `X`  | `numpy.ndarray` |         | Data.       |

**Returns**

* Type: `numpy.ndarray`

#### `filter_by_probability_knn`

```python
filter_by_probability_knn(X: numpy.ndarray, Y: numpy.ndarray) -> Tuple[numpy.ndarray, numpy.ndarray]
```

| Name | Type            | Default | Description             |
| ---- | --------------- | ------- | ----------------------- |
| `X`  | `numpy.ndarray` |         | Data.                   |
| `Y`  | `numpy.ndarray` |         | Predicted class labels. |

**Returns**

* Type: `Tuple[numpy.ndarray, numpy.ndarray]`

#### `fit`

```python
fit(X: numpy.ndarray, Y: numpy.ndarray, classes: Optional[int] = None) -> None
```

| Name      | Type            | Default | Description                                                                           |
| --------- | --------------- | ------- | ------------------------------------------------------------------------------------- |
| `X`       | `numpy.ndarray` |         | Data.                                                                                 |
| `Y`       | `numpy.ndarray` |         | Target labels, either one-hot encoded or the actual class label.                      |
| `classes` | `Optional[int]` | `None`  | Number of prediction classes, needs to be provided if `Y` equals the predicted class. |

**Returns**

* Type: `None`

#### `score`

```python
score(X: numpy.ndarray, Y: numpy.ndarray, k: int = 2, dist_type: str = 'point') -> Tuple[numpy.ndarray, numpy.ndarray]
```

| Name        | Type            | Default   | Description                                                                                                                                                              |
| ----------- | --------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `X`         | `numpy.ndarray` |           | Instances to calculate trust score for.                                                                                                                                  |
| `Y`         | `numpy.ndarray` |           | Either prediction probabilities for each class or the predicted class.                                                                                                   |
| `k`         | `int`           | `2`       | Number of nearest neighbors used for distance calculation.                                                                                                               |
| `dist_type` | `str`           | `'point'` | Use either the distance to the k-nearest point (`dist_type = 'point'`) or the average distance from the first to the k-nearest point in the data (`dist_type = 'mean'`). |

**Returns**

* Type: `Tuple[numpy.ndarray, numpy.ndarray]`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seldon.ai/alibi-explain/api-reference/confidence/trustscore.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
