Skip to content

Commit 7416bed

Browse files
authored
[FSTORE-1181][APPEND] use date until card expires in helper columns example (#358)
use date until card expires in helper columns example
1 parent 8dcf0e3 commit 7416bed

File tree

1 file changed

+16
-24
lines changed

1 file changed

+16
-24
lines changed

docs/user_guides/fs/feature_view/helper-columns.md

+16-24
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ Hopsworks Feature Store provides a functionality to define two types of helper c
1010
to the original column name when defining helper column list.
1111

1212
## Inference Helper columns
13-
`inference_helper_columns` are a list of feature names that are not used for training the model itself but are used for extra information during online or batch inference.
14-
For example computing [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md) like distance between previous and current place of transaction `loc_delta_t_minus_1` in credit card fraud detection system.
15-
Feature `loc_delta_t_minus_1` will be computed using previous transaction coordinates `longitude` and `latitude` that needs to fetched from the feature store and compared to the new transaction coordinates that arrives at inference application.
16-
In this use case `longitude` and `latitude` are `inference_helper_columns`. They are not used for training but are necessary for computing [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md) `loc_delta_t_minus_1`.
13+
`inference_helper_columns` are a list of feature names that are not used for training the model itself but are used for extra information during online or batch inference.
14+
For example, computing an [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md) such as `days_valid` (days left that a credit card is valid at the time of the transaction)
15+
in a credit card fraud detection system. The feature `days_valid` will be computed using the credit card expiry date that needs to be fetched from the feature store and compared to the transaction
16+
date that the transaction is performed on (`days_valid` = `expiry_date` - `current_date`). In this use case `expiry_date` is an inference helper column. It is not used for training but is necessary
17+
for computing the [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md)`days_valid` feature.
18+
1719

1820
=== "Python"
1921

2022
!!! example "Define inference columns for feature views."
2123
```python
2224
# define query object
2325
query = label_fg.select("fraud_label")\
24-
.join(trans_fg.select(["amount", "loc_delta_t_minus_1", "longitude", "latitude", "category"]))
26+
.join(trans_fg.select(["amount", "days_valid", "expiry_date", "category"]))
2527
2628
# define feature view with helper columns
2729
feature_view = fs.get_or_create_feature_view(
@@ -30,7 +32,7 @@ In this use case `longitude` and `latitude` are `inference_helper_columns`. They
3032
query=query,
3133
labels=["fraud_label"],
3234
transformation_functions=transformation_functions,
33-
inference_helper_columns=["longitude", "latitude"],
35+
inference_helper_columns=["expiry_date"],
3436
)
3537
```
3638

@@ -45,7 +47,7 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
4547
```python
4648

4749
# import feature functions
48-
from feature_functions import location_delta, time_delta
50+
from feature_functions import time_delta
4951
5052
# Fetch feature view object
5153
feature_view = fs.get_feature_view(
@@ -54,15 +56,10 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
5456
)
5557

5658
# Fetch feature data for batch inference with helper columns
57-
df = feature_view.get_batch_data(start_time=start_time, end_time=end_time, inference_helpers=True)
58-
df['longitude_prev'] = df['longitude'].shift(-1)
59-
df['latitute_prev'] = df['latitute'].shift(-1)
59+
df = feature_view.get_batch_data(start_time=start_time, end_time=end_time, inference_helpers=True, event_time=True)
6060

6161
# compute location delta
62-
df['loc_delta_t_minus_1'] = df.apply(lambda row: location_delta(row['longitude'],
63-
row['latitute'],
64-
row['longitude_prev'],
65-
row['latitute_prev']), axis=1)
62+
df['days_valid'] = df.apply(lambda row: time_delta(row['expiry_date'], row['transaction_date']), axis=1)
6663

6764
# prepare datatame for prediction
6865
df = df[[f.name for f in feature_view.features if not (f.label or f.inference_helper_column or f.training_helper_column)]]
@@ -75,7 +72,7 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
7572
!!! example "Fetch inference helper column values and compute on-demand features during online inference."
7673
```python
7774

78-
from feature_functions import location_delta, time_delta
75+
from feature_functions import time_delta
7976
8077
# Fetch feature view object
8178
feature_view = fs.get_feature_view(
@@ -91,22 +88,17 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
9188

9289
# here cc_num, longitute and lattitude are provided as parameters to the application
9390
cc_num = ...
94-
longitude = ...
95-
latitute = ...
91+
transaction_date = ...
9692
9793
# get previous transaction location of this credit card
9894
inference_helper = feature_view.get_inference_helper({"cc_num": cc_num}, return_type="dict")
9995

10096
# compute location delta
101-
loc_delta_t_minus_1 = location_delta(longitude,
102-
latitute,
103-
inference_helper['longitude'],
104-
inference_helper['latitute'])
105-
97+
days_valid = time_delta(transaction_date, inference_helper['expiry_date'])
10698

10799
# Now get assembled feature vector for prediction
108100
feature_vector = feature_view.get_feature_vector({"cc_num": cc_num},
109-
passed_features={"loc_delta_t_minus_1": loc_delta_t_minus_1}
101+
passed_features={"days_valid": days_valid}
110102
)
111103
```
112104

@@ -121,7 +113,7 @@ For example one might want to use feature like `category` of the purchased produ
121113
```python
122114
# define query object
123115
query = label_fg.select("fraud_label")\
124-
.join(trans_fg.select(["amount", "loc_delta_t_minus_1", "longitude", "latitude", "category"]))
116+
.join(trans_fg.select(["amount", "days_valid", "expiry_date", "category"]))
125117
126118
# define feature view with helper columns
127119
feature_view = fs.get_or_create_feature_view(

0 commit comments

Comments
 (0)