# Segments

### Overview

A segment, sometimes referred to as a cohort or slice, represents a distinct subset of model values crucial for performance analysis and troubleshooting. Model segments can be defined using various model dimensions, such as specific time periods or sets of features. Analyzing segments proves invaluable for understanding or troubleshooting specific cohorts of interest, particularly in tasks like bias detection, where overarching datasets might obscure statistical intricacies.

### How to Define a Segment

Fiddler makes it easy to define custom segments using either the Fiddler UI or the Fiddler Python client. Instructions for both approaches are covered in more detail below. In either case, Fiddler Segments are constructed using the [Fiddler Query Language (FQL)](https://docs.fiddler.ai/observability/platform/fiddler-query-language).

You can use any of the constants, operators, and functions mentioned in the page linked above in a Segment definition.

However, every Segment definition must return **a boolean row-level expression**. In other words, each inference will either satisfy the segment expression and thus belong to the segment or it will not.

### Examples

Let us illustrate further by providing a few examples. A segment can be defined by:

* A condition on some column (e.g. `age > 50`)
* A condition on some combination of columns (e.g. `(age / max_age) < 1.0`)

For details on all supported functions, see the [Fiddler Query Language (FQL)](https://docs.fiddler.ai/observability/platform/fiddler-query-language) page.

### Adding a Segment Using the Python Client

```python
model_id = 'your_model_identifier'
segment_name = 'your_segment_name'

model = fdl.Model.get(id_=model_id)

# Use Fiddler Query Language (FQL) to define your custom segments
segment = fdl.Segment(
    name=segment_name,
    model_id=model.id,
    definition="Age < 60",  
    description='Users with Age under 60',
).create()
```

### Applied Segments

When using segments in the UI for Analytics or Monitoring Charts, applied segments offer a flexible way to define segments on the fly for exploratory analysis. These segments are not saved to the model by default, but will persist locally if the chart they are applied to is saved.

At any time, an applied segment can be saved to the model. However, once a segment is saved to the model, it cannot be altered.

### Modifying Saved Segments

Since alerts can be set on Segments, making modifications to a Segment may introduce inconsistencies in alerts.

> 🚧 Therefore, **Saved segments cannot be modified once they are created**.

If you'd like to experiment with a new segment, you can create one with a different definition or use applied segments within charts.

#### Deleting Segments

Delete a segment using the [Python client SDK](https://app.gitbook.com/s/rsvU8AIQ2ZL9arerribd/fiddler-python-client-sdk). Alternatively, from the segments tab, you can delete a segment by clicking the trash icon next to the segment record.

![](https://3170638587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F82RHcnYWV62fvrxMeeBB%2Fuploads%2Fgit-blob-ed9e66ca2fd5d8d2de4dee32a7a1eac2b43e985e%2F5789f6c-image.png?alt=media)


---

# Agent Instructions: 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.fiddler.ai/observability/platform/segments.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.
