-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathfeatures.py
More file actions
201 lines (183 loc) · 5.66 KB
/
features.py
File metadata and controls
201 lines (183 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
from datetime import timedelta
import pandas as pd
from feast import Entity, FeatureService, FeatureView, Field, FileSource
from feast.data_source import RequestSource
from feast.on_demand_feature_view import on_demand_feature_view
from feast.types import Bool, Int64, String
zipcode = Entity(
name="zipcode",
description="A zipcode",
tags={
"owner": "danny@feast.ai",
"team": "hack week",
},
)
zipcode_source = FileSource(
name="zipcode",
path="data/zipcode_table.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created_timestamp",
)
zipcode_features = FeatureView(
name="zipcode_features",
entities=[zipcode],
ttl=timedelta(days=3650),
schema=[
Field(name="city", dtype=String),
Field(name="state", dtype=String),
Field(name="location_type", dtype=String),
Field(name="tax_returns_filed", dtype=Int64),
Field(name="population", dtype=Int64),
Field(name="total_wages", dtype=Int64),
Field(name="zipcode", dtype=Int64),
],
source=zipcode_source,
tags={
"date_added": "2022-02-7",
"experiments": "experiment-A,experiment-B,experiment-C",
"access_group": "feast-team@feast.ai",
},
online=True,
)
zipcode_features = FeatureView(
name="zipcode_features",
entities=[zipcode],
ttl=timedelta(days=3650),
schema=[
Field(name="city", dtype=String),
Field(name="state", dtype=String),
Field(name="location_type", dtype=String),
Field(name="tax_returns_filed", dtype=Int64),
Field(name="population", dtype=Int64),
Field(name="total_wages", dtype=Int64),
Field(name="zipcode", dtype=Int64),
],
source=zipcode_source,
tags={
"date_added": "2022-02-7",
"experiments": "experiment-A,experiment-B,experiment-C",
"access_group": "feast-team@feast.ai",
},
online=True,
)
zipcode_money_features = FeatureView(
name="zipcode_money_features",
entities=[zipcode],
ttl=timedelta(days=3650),
schema=[
Field(name="tax_returns_filed", dtype=Int64),
Field(name="total_wages", dtype=Int64),
Field(name="zipcode", dtype=Int64),
],
source=zipcode_source,
tags={
"date_added": "2022-02-7",
"experiments": "experiment-A,experiment-B,experiment-C",
"access_group": "feast-team@feast.ai",
},
online=True,
)
dob_ssn = Entity(
name="dob_ssn",
description="Date of birth and last four digits of social security number",
tags={
"owner": "tony@feast.ai",
"team": "hack week",
},
)
credit_history_source = FileSource(
name="credit_history",
path="data/credit_history.parquet",
timestamp_field="event_timestamp",
created_timestamp_column="created_timestamp",
)
credit_history = FeatureView(
name="credit_history",
entities=[dob_ssn],
ttl=timedelta(days=9000),
schema=[
Field(name="credit_card_due", dtype=Int64),
Field(name="mortgage_due", dtype=Int64),
Field(name="student_loan_due", dtype=Int64),
Field(name="vehicle_loan_due", dtype=Int64),
Field(name="hard_pulls", dtype=Int64),
Field(name="missed_payments_2y", dtype=Int64),
Field(name="missed_payments_1y", dtype=Int64),
Field(name="missed_payments_6m", dtype=Int64),
Field(name="bankruptcies", dtype=Int64),
Field(name="dob_ssn", dtype=String),
],
source=credit_history_source,
tags={
"date_added": "2022-02-6",
"experiments": "experiment-A",
"access_group": "feast-team@feast.ai",
},
online=True,
)
# Define a request data source which encodes features / information only
# available at request time (e.g. part of the user initiated HTTP request)
input_request = RequestSource(
name="transaction",
schema=[
Field(name="transaction_amt", dtype=Int64),
],
)
# Define an on demand feature view which can generate new features based on
# existing feature views and RequestSource features
@on_demand_feature_view(
sources=[credit_history, input_request],
schema=[
Field(name="transaction_gt_last_credit_card_due", dtype=Bool),
],
)
def transaction_gt_last_credit_card_due(inputs: pd.DataFrame) -> pd.DataFrame:
df = pd.DataFrame()
df["transaction_gt_last_credit_card_due"] = (
inputs["transaction_amt"] > inputs["credit_card_due"]
)
return df
model_v1 = FeatureService(
name="credit_score_v1",
features=[
credit_history[["credit_card_due", "missed_payments_1y"]],
zipcode_features,
],
tags={"owner": "tony@feast.ai", "stage": "staging"},
description="Credit scoring model",
)
model_v2 = FeatureService(
name="credit_score_v2",
features=[
credit_history[["mortgage_due", "credit_card_due", "missed_payments_1y"]],
zipcode_features,
],
tags={"owner": "tony@feast.ai", "stage": "prod"},
description="Credit scoring model",
)
model_v3 = FeatureService(
name="credit_score_v3",
features=[
credit_history[["mortgage_due", "credit_card_due", "missed_payments_1y"]],
zipcode_features,
transaction_gt_last_credit_card_due,
],
tags={"owner": "tony@feast.ai", "stage": "dev"},
description="Credit scoring model",
)
zipcode_model = FeatureService(
name="zipcode_model",
features=[
zipcode_features,
],
tags={"owner": "amanda@feast.ai", "stage": "dev"},
description="Location model",
)
zipcode_model_v2 = FeatureService(
name="zipcode_model_v2",
features=[
zipcode_money_features,
],
tags={"owner": "amanda@feast.ai", "stage": "dev"},
description="Location model",
)