Skip to content

Commit a0b9c09

Browse files
author
davitbzh
committed
days until card expires example
1 parent edb6afd commit a0b9c09

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

Diff for: docs/user_guides/fs/feature_view/helper-columns.md

+13-23
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ Hopsworks Feature Store provides a functionality to define two types of helper c
1111

1212
## Inference Helper columns
1313
`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`.
14+
For example computing [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md) like days left until credit card is valid at the time of transaction `days_until_valid` in credit card fraud detection system.
15+
Feature `days_until_valid` will be computed using credit cart valid through date `cc_valid_through` that needs to fetched from the feature store and compared to the new transaction date that arrives at
16+
inference application. In this use case `cc_valid_through` are `inference_helper_column`. It is not used for training but is necessary for computing [on-demand feature](../../../concepts/fs/feature_group/on_demand_feature.md) `days_until_valid`.
1717

1818
=== "Python"
1919

2020
!!! example "Define inference columns for feature views."
2121
```python
2222
# define query object
2323
query = label_fg.select("fraud_label")\
24-
.join(trans_fg.select(["amount", "loc_delta_t_minus_1", "longitude", "latitude", "category"]))
24+
.join(trans_fg.select(["amount", "days_until_valid", "cc_valid_through", "category"]))
2525
2626
# define feature view with helper columns
2727
feature_view = fs.get_or_create_feature_view(
@@ -30,7 +30,7 @@ In this use case `longitude` and `latitude` are `inference_helper_columns`. They
3030
query=query,
3131
labels=["fraud_label"],
3232
transformation_functions=transformation_functions,
33-
inference_helper_columns=["longitude", "latitude"],
33+
inference_helper_columns=["cc_valid_through"],
3434
)
3535
```
3636

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

4747
# import feature functions
48-
from feature_functions import location_delta, time_delta
48+
from feature_functions import time_delta
4949
5050
# Fetch feature view object
5151
feature_view = fs.get_feature_view(
@@ -54,15 +54,10 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
5454
)
5555

5656
# 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)
57+
df = feature_view.get_batch_data(start_time=start_time, end_time=end_time, inference_helpers=True, event_time=True)
6058

6159
# 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)
60+
df['days_until_valid'] = df.apply(lambda row: time_delta(row['cc_valid_through'], row['transaction_date']), axis=1)
6661

6762
# prepare datatame for prediction
6863
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 +70,7 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
7570
!!! example "Fetch inference helper column values and compute on-demand features during online inference."
7671
```python
7772

78-
from feature_functions import location_delta, time_delta
73+
from feature_functions import time_delta
7974
8075
# Fetch feature view object
8176
feature_view = fs.get_feature_view(
@@ -91,22 +86,17 @@ When retrieving data for model inference, helper columns will be omitted. Howeve
9186

9287
# here cc_num, longitute and lattitude are provided as parameters to the application
9388
cc_num = ...
94-
longitude = ...
95-
latitute = ...
89+
transaction_date = ...
9690
9791
# get previous transaction location of this credit card
9892
inference_helper = feature_view.get_inference_helper({"cc_num": cc_num}, return_type="dict")
9993

10094
# compute location delta
101-
loc_delta_t_minus_1 = location_delta(longitude,
102-
latitute,
103-
inference_helper['longitude'],
104-
inference_helper['latitute'])
105-
95+
days_until_valid = time_delta(transaction_date, inference_helper['cc_valid_through'])
10696

10797
# Now get assembled feature vector for prediction
10898
feature_vector = feature_view.get_feature_vector({"cc_num": cc_num},
109-
passed_features={"loc_delta_t_minus_1": loc_delta_t_minus_1}
99+
passed_features={"days_until_valid": days_until_valid}
110100
)
111101
```
112102

@@ -121,7 +111,7 @@ For example one might want to use feature like `category` of the purchased produ
121111
```python
122112
# define query object
123113
query = label_fg.select("fraud_label")\
124-
.join(trans_fg.select(["amount", "loc_delta_t_minus_1", "longitude", "latitude", "category"]))
114+
.join(trans_fg.select(["amount", "days_until_valid", "cc_valid_through", "category"]))
125115
126116
# define feature view with helper columns
127117
feature_view = fs.get_or_create_feature_view(

0 commit comments

Comments
 (0)