Skip to content

featurebyte.Feature.cd.unique_count

unique_count(
include_missing: bool=True
) -> Feature

Description

Computes number of distinct keys in a Cross Aggregate feature.

Parameters

  • include_missing: bool
    default: True
    Whether to include missing value when counting the number of distinct keys.

Returns

  • Feature
    A new Feature object.

Examples

Create a new feature by counting the number of keys in the dictionary feature:

>>> counts = catalog.get_feature("CustomerProductGroupCounts_7d")
>>> new_feature = counts.cd.unique_count()
>>> new_feature.name = "CustomerProductGroupCountsUniqueCount_7d"
Preview the features:

>>> features = fb.FeatureGroup([counts, new_feature])
>>> df = features.preview(
...     pd.DataFrame([
...         {
...             "POINT_IN_TIME": "2022-04-15 10:00:00",
...             "GROCERYCUSTOMERGUID": "2f4c1578-29d6-44b7-83da-7c5bfb981fa0",
...         }
...     ])
... )

Dictionary feature:

>>> df["CustomerProductGroupCounts_7d"].iloc[0]
{'Chips et Tortillas': 1, 'Colas, Thés glacés et Sodas': 3, 'Crèmes et Chantilly': 1, 'Pains': 1, 'Œufs': 1}

New feature:

>>> df["CustomerProductGroupCountsUniqueCount_7d"].iloc[0]
5.0