Skip to content

featurebyte.Feature.cd.key_with_highest_value

key_with_highest_value( ) -> Feature

Description

Retrieves the key with the highest value in the Cross Aggregate feature. When there are ties, the lexicographically smallest key is returned.

This is an alias for most_frequent().

Returns

  • Feature
    A new feature object.

Examples

Create a new feature by retrieving the key with the highest value of the dictionary feature:

>>> counts = catalog.get_feature("CustomerProductGroupTotalCost_7d")
>>> new_feature = counts.cd.key_with_highest_value()
>>> new_feature.name = "CustomerProductGroupWithHighestTotalCost_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["CustomerProductGroupTotalCost_7d"].iloc[0]
'{"Chips et Tortillas":2.0,"Colas, Thés glacés et Sodas":10.0,"Crèmes et Chantilly":0.75,"Pains":1.09,"Œufs":1.19}'
New feature:

>>> df["CustomerProductGroupWithHighestTotalCost_7d"].iloc[0]
'Colas, Thés glacés et Sodas'