featurebyte.Feature.cd.entropy¶
entropy( ) -> Feature
Description¶
Computes the entropy of the Cross Aggregate feature over the feature keys. The values are normalized to sum to 1 and used as the probability of each key in the entropy calculation.
Returns¶
- Feature
A new Feature object.
Examples¶
Create a new feature by calculating the entropy of the dictionary feature:
>>> counts = catalog.get_feature("CustomerProductGroupCounts_7d")
>>> new_feature = counts.cd.entropy()
>>> new_feature.name = "CustomerProductGroupCountsEntropy_7d"
>>> 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"}]))
>>> 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: