5. Create segment

Segment creation requires that you define a set of filters that need to be applied to models in your project.
Segments can be active or archived.

  • Active segment - For any new data sent to the platform, metrics will be computed for this segment.
  • Archived segment - The segment is still available for historical analysis, but new data metrics won't be computed for this segment.

Creating segments is an optional step and not mandatory, but it is recommended, as segments can be applied only on data sent after their creation.

📘

Segment conditions builder

The possible entetites that can take part of the segment definition are:

  • Any entity under the role of: "Feature", "Prediction probability", "Prediction value" or "Metadata"
  • Categorical entities with more than 250 distinct values cannot be used for a segment filter

Create a segment via the console

  1. Step into the "Segments" screen and click "Create Segment" or click on the "Create segment" button in the model's screen (that appears when hovering a model)

  1. Create the segment - give it a meaningful name and select the filters that define the segment (sub population). Available operators between filters are AND and OR

Create a segment via SDK

📘

install the SDK

To install and get started with our SDK visit our SDK docs

A segment can be constructed from one or more definitions, with OR or AND operators between them.
The definitions are represented by AOA (array of arrays).
Elements in the inner arrays are conditioned with OR between them, and elements in the outer array (OR arrays) are conditioned with AND, which allows the expression of any possible sub-populations (in a CNF-like conditioning structure).

In the following example, the definitions are:
cut entity value in [Premium, Ideal] OR color entity value = D
AND carat entity value > 1

from superwise.models.segment import Segment
from superwise.models.segment import SegmentCondition
from superwise.models.segment import SegmentConditionDefinition

segment = Segment(
    project_id=1,
    name="top_diamonds",
    definition=[
        [SegmentConditionDefinition(
            entity_id=1,
            condition=SegmentCondition.IN,
            value=["Premium", "Ideal"],
        ),
            SegmentConditionDefinition(
                entity_id=2,
                condition=SegmentCondition.EQUALS,
                value="D"
            )
        ],
        [SegmentConditionDefinition(
            entity_id=3,
            condition=SegmentCondition.GREATER_THAN,
            value=1
        )],
    ],
)
segment = sw.segment.create(segment)
print(segment.get_properties())

To read more on the available segment condition operators visit our SDK reference guide