Documentation

Guides

Request Based Features

Many ML features in real world ML systems like recommendations or fraud detection depend on the context of the user request. Such features and their dependencies are very naturally modeled in Fennel. Let's look at one good way of doing this:

1@featureset
2class SearchRequest:
3    time: datetime = feature(id=1)
4    ip: str = feature(id=2)
5    device_type: str = feature(id=3)
6    query: str = feature(id=4)
7
8@featureset
9class UserFeatures:
10    uid: int = feature(id=1)
11    ...
12    ctr_by_device_type: float = feature(id=17)
13    ..
14
15    @extractor
16    @inputs(SearchRequest.device_type)
17    @outputs(ctr_by_device_type)
18    def f(cls, ts: pd.Series, devices: pd.Series):
19        for device in devices:
20            ...
21
22

In this example, we defined a featureset called SearchRequest that contains all the properties of the request that are relevant for a feature. This featureset itself has no extractors - Fennel doesn't know how to extract any of these features.

Features of other featuresets can now depend on SearchRequest features - in this example some features of UserFeatures are depending on SearchRequest.device_type. This way, as long as SearchRequest features are passed as input to extraction process, all such other features can be naturally computed.

This makes it very easy to mix and match computation & data lookups based on some request properties.