Skip to content

Commit 64d29dd

Browse files
authored
4.0 release
1 parent 724817d commit 64d29dd

39 files changed

+2435
-1268
lines changed

advanced_tutorials/air_quality/1_air_quality_feature_backfill.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,7 @@
11311131
],
11321132
"metadata": {
11331133
"kernelspec": {
1134-
"display_name": "Python 3",
1134+
"display_name": "Python 3 (ipykernel)",
11351135
"language": "python",
11361136
"name": "python3"
11371137
},
@@ -1145,7 +1145,7 @@
11451145
"name": "python",
11461146
"nbconvert_exporter": "python",
11471147
"pygments_lexer": "ipython3",
1148-
"version": "3.10.11"
1148+
"version": "3.8.18"
11491149
}
11501150
},
11511151
"nbformat": 4,

advanced_tutorials/aml/2_aml_training_pipeline.ipynb

+10-10
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,16 @@
151151
"min_max_scaler = fs.get_transformation_function(name=\"min_max_scaler\")\n",
152152
"\n",
153153
"# Map features to transformations.\n",
154-
"transformation_functions = {\n",
155-
" \"monthly_in_count\": min_max_scaler,\n",
156-
" \"monthly_in_total_amount\": min_max_scaler,\n",
157-
" \"monthly_in_mean_amount\": min_max_scaler,\n",
158-
" \"monthly_in_std_amount\": min_max_scaler,\n",
159-
" \"monthly_out_count\": min_max_scaler,\n",
160-
" \"monthly_out_total_amount\": min_max_scaler,\n",
161-
" \"monthly_out_mean_amount\": min_max_scaler,\n",
162-
" \"monthly_out_std_amount\": min_max_scaler,\n",
163-
"}"
154+
"transformation_functions = [\n",
155+
" min_max_scaler(\"monthly_in_count\"),\n",
156+
" min_max_scaler(\"monthly_in_total_amount\"),\n",
157+
" min_max_scaler(\"monthly_in_mean_amount\"),\n",
158+
" min_max_scaler(\"monthly_in_std_amount\"),\n",
159+
" min_max_scaler(\"monthly_out_count\"),\n",
160+
" min_max_scaler(\"monthly_out_total_amount\"),\n",
161+
" min_max_scaler(\"monthly_out_mean_amount\"),\n",
162+
" min_max_scaler(\"monthly_out_std_amount\"),\n",
163+
"]"
164164
]
165165
},
166166
{

advanced_tutorials/bitcoin/3_bitcoin_training_pipeline.ipynb

+14-14
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"min_max_scaler = fs.get_transformation_function(name=\"min_max_scaler\")\n",
215215
"\n",
216216
"# Map features to transformation functions.\n",
217-
"transformation_functions = {col: min_max_scaler for col in columns_to_transform}"
217+
"transformation_functions = [min_max_scaler(col) for col in columns_to_transform]"
218218
]
219219
},
220220
{
@@ -522,22 +522,22 @@
522522
"metadata": {},
523523
"outputs": [],
524524
"source": [
525-
"import inspect \n",
526-
"# Recall that you applied transformation functions, such as min max scaler and laber encoder. \n",
527-
"# Now you want to transform them back to human readable format.\n",
525+
"# Initializing serving\n",
528526
"feature_view.init_serving(1)\n",
529-
"td_transformation_functions = feature_view._single_vector_server._transformation_functions\n",
527+
"\n",
528+
"# Accessing the transformation functions used in the serving configuration\n",
529+
"fv_transformation_functions = feature_view._vector_server.model_dependent_transformation_functions\n",
530530
"\n",
531531
"y_pred = pd.DataFrame(y_pred_scaled, columns=[\"close\"])\n",
532532
"\n",
533-
"for feature_name in td_transformation_functions:\n",
534-
" if feature_name == \"close\":\n",
535-
" td_transformation_function = td_transformation_functions[feature_name]\n",
536-
" sig, foobar_locals = inspect.signature(td_transformation_function.transformation_fn), locals()\n",
537-
" param_dict = dict([(param.name, param.default) for param in sig.parameters.values() if param.default != inspect._empty])\n",
538-
" if td_transformation_function.name == \"min_max_scaler\":\n",
539-
" y_pred[feature_name] = y_pred[feature_name].map(lambda x: x*(param_dict[\"max_value\"]-param_dict[\"min_value\"])+param_dict[\"min_value\"])\n",
540-
" y_test[feature_name] = y_test[feature_name].map(lambda x: x*(param_dict[\"max_value\"]-param_dict[\"min_value\"])+param_dict[\"min_value\"])"
533+
"for transformation_function in fv_transformation_functions:\n",
534+
" udf = transformation_function.hopsworks_udf\n",
535+
" transformation_feature = udf.transformation_features[0]\n",
536+
" transformed_feature = udf.transformation_features[0]\n",
537+
" if transformed_feature == \"close\" and udf.function_name == \"min_max_scaler\":\n",
538+
" stats = udf.transformation_statistics\n",
539+
" y_pred[transformation_feature] = y_pred[transformation_feature].map(lambda x: x*(stats.feature.max-stats.feature.min)+stats.feature.min)\n",
540+
" y_test[transformed_feature] = y_test[transformed_feature].map(lambda x: x*(stats.feature.max-stats.feature.min)+stats.feature.min)"
541541
]
542542
},
543543
{
@@ -996,7 +996,7 @@
996996
"name": "python",
997997
"nbconvert_exporter": "python",
998998
"pygments_lexer": "ipython3",
999-
"version": "3.9.12"
999+
"version": "3.12.5"
10001000
},
10011001
"vscode": {
10021002
"interpreter": {

advanced_tutorials/credit_scores/3_credit_scores_training_pipeline.ipynb

+4-4
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@
261261
"outputs": [],
262262
"source": [
263263
"# Retrieving the names of all available transformation functions\n",
264-
"[t_func.name for t_func in fs.get_transformation_functions()]"
264+
"[t_func for t_func in fs.get_transformation_functions()]"
265265
]
266266
},
267267
{
@@ -290,11 +290,11 @@
290290
"label_encoder = fs.get_transformation_function(name='label_encoder') \n",
291291
"\n",
292292
"# Creating a dictionary of transformation functions, where each categorical column is associated with the Label Encoder\n",
293-
"transformation_functions = {\n",
294-
" col: label_encoder\n",
293+
"transformation_functions = [\n",
294+
" label_encoder(col)\n",
295295
" for col \n",
296296
" in cat_cols\n",
297-
"}"
297+
"]"
298298
]
299299
},
300300
{

advanced_tutorials/electricity/3_electricity_training_pipeline.ipynb

+19-15
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,25 @@
163163
"# List of price areas\n",
164164
"price_areas = [\"se1\", \"se2\", \"se3\", \"se4\"]\n",
165165
"\n",
166+
"# Retrieving transformation functions\n",
167+
"min_max_scaler = fs.get_transformation_function(name=\"min_max_scaler\")\n",
168+
"label_encoder = fs.get_transformation_function(name='label_encoder')\n",
169+
"\n",
166170
"# Mapping features to their respective transformation functions\n",
167-
"mapping_transformers = {}\n",
171+
"transformation_functions = []\n",
168172
"\n",
169173
"# Iterate through each price area and map features to their transformation functions\n",
170174
"for area in price_areas:\n",
171-
" mapping_transformers[f\"price_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\")\n",
172-
" mapping_transformers[f\"mean_temp_per_day_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\")\n",
173-
" mapping_transformers[f\"mean_wind_speed_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\")\n",
174-
" mapping_transformers[f\"precipitaton_amount_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\")\n",
175-
" mapping_transformers[f\"total_sunshine_time_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\")\n",
176-
" mapping_transformers[f\"mean_cloud_perc_{area}\"] = fs.get_transformation_function(name=\"min_max_scaler\") \n",
177-
" mapping_transformers[f\"precipitaton_type_{area}\"] = fs.get_transformation_function(name='label_encoder')\n",
175+
" transformation_functions.append(min_max_scaler(f\"price_{area}\"))\n",
176+
" transformation_functions.append(min_max_scaler(f\"mean_temp_per_day_{area}\"))\n",
177+
" transformation_functions.append(min_max_scaler(f\"mean_wind_speed_{area}\"))\n",
178+
" transformation_functions.append(min_max_scaler(f\"precipitaton_amount_{area}\"))\n",
179+
" transformation_functions.append(min_max_scaler(f\"total_sunshine_time_{area}\"))\n",
180+
" transformation_functions.append(min_max_scaler(f\"mean_cloud_perc_{area}\"))\n",
181+
" transformation_functions.append(label_encoder(f\"precipitaton_type_{area}\"))\n",
178182
"\n",
179183
"# Additional transformation for 'type_of_day'\n",
180-
"mapping_transformers[\"type_of_day\"] = fs.get_transformation_function(name='label_encoder')"
184+
"transformation_functions.append(label_encoder(\"type_of_day\"))"
181185
]
182186
},
183187
{
@@ -215,7 +219,7 @@
215219
" name='electricity_feature_view',\n",
216220
" version=1,\n",
217221
" labels=[], # you will define our 'y' later manualy\n",
218-
" transformation_functions=mapping_transformers,\n",
222+
" transformation_functions=transformation_functions,\n",
219223
" query=selected_features,\n",
220224
")"
221225
]
@@ -304,9 +308,9 @@
304308
"outputs": [],
305309
"source": [
306310
"# Define 'y_train', 'y_val' and 'y_test'\n",
307-
"y_train = X_train[[\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"]]\n",
308-
"y_val = X_val[[\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"]]\n",
309-
"y_test = X_test[[\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"]]"
311+
"y_train = X_train[[\"min_max_scaler_price_se1_\", \"min_max_scaler_price_se2_\", \"min_max_scaler_price_se3_\", \"min_max_scaler_price_se4_\"]]\n",
312+
"y_val = X_val[[\"min_max_scaler_price_se1_\", \"min_max_scaler_price_se2_\", \"min_max_scaler_price_se3_\", \"min_max_scaler_price_se4_\"]]\n",
313+
"y_test = X_test[[\"min_max_scaler_price_se1_\", \"min_max_scaler_price_se2_\", \"min_max_scaler_price_se3_\", \"min_max_scaler_price_se4_\"]]"
310314
]
311315
},
312316
{
@@ -494,7 +498,7 @@
494498
" input_width=4, \n",
495499
" label_width=4, \n",
496500
" shift=1, \n",
497-
" label_columns=[\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"],\n",
501+
" label_columns=[\"min_max_scaler_price_se1_\", \"min_max_scaler_price_se2_\", \"min_max_scaler_price_se3_\", \"min_max_scaler_price_se4_\"],\n",
498502
")\n",
499503
"\n",
500504
"# Displaying the WindowGenerator instance\n",
@@ -710,7 +714,7 @@
710714
"source": [
711715
"# Plotting the time series data for the 'price_se4' column\n",
712716
"n_step_window.plot(\n",
713-
" plot_col=\"price_se4\", \n",
717+
" plot_col=\"min_max_scaler_price_se4_\", \n",
714718
" max_subplots=3, \n",
715719
" model=model.predict,\n",
716720
")"

advanced_tutorials/electricity/4_electricity_batch_inference.ipynb

+8-11
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"feature_view.init_serving(1)\n",
251251
"\n",
252252
"# Accessing the transformation functions used in the serving configuration\n",
253-
"td_transformation_functions = feature_view._batch_scoring_server._transformation_functions"
253+
"fv_transformation_functions = feature_view._vector_server.model_dependent_transformation_functions"
254254
]
255255
},
256256
{
@@ -268,15 +268,12 @@
268268
"\n",
269269
"# Extracting and decoding the transformation functions used in serving\n",
270270
"res = {}\n",
271-
"for feature_name in td_transformation_functions:\n",
272-
" if feature_name in [\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"]:\n",
273-
" td_transformation_function = td_transformation_functions[feature_name]\n",
274-
" sig, foobar_locals = inspect.signature(td_transformation_function.transformation_fn), locals()\n",
275-
" param_dict = dict([(param.name, param.default) for param in sig.parameters.values() if param.default != inspect._empty])\n",
276-
" if td_transformation_function.name == \"min_max_scaler\":\n",
277-
" preds[feature_name] = preds[feature_name].map(\n",
278-
" lambda x: x * (param_dict[\"max_value\"] - param_dict[\"min_value\"]) + param_dict[\"min_value\"]\n",
279-
" )\n",
271+
"for transformation_function in fv_transformation_functions:\n",
272+
" udf = transformation_function.hopsworks_udf\n",
273+
" transformed_features = udf.transformation_features[0]\n",
274+
" if transformed_features in [\"price_se1\", \"price_se2\", \"price_se3\", \"price_se4\"] and udf.function_name == \"min_max_scaler\":\n",
275+
" stats = udf.transformation_statistics\n",
276+
" preds[transformed_features] = preds[transformed_features].map(lambda x: x*(stats.feature.max-stats.feature.min)+stats.feature.min)\n",
280277
"\n",
281278
"# Applying a transformation to reverse the sign of the decoded features\n",
282279
"preds = preds.apply(lambda x: -x)\n",
@@ -336,7 +333,7 @@
336333
"name": "python",
337334
"nbconvert_exporter": "python",
338335
"pygments_lexer": "ipython3",
339-
"version": "3.9.18"
336+
"version": "3.12.5"
340337
}
341338
},
342339
"nbformat": 4,

advanced_tutorials/hospital_wait_time/2_training_pipeline.ipynb

+9-9
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
"metadata": {},
130130
"outputs": [],
131131
"source": [
132-
"[f.name for f in fs.get_transformation_functions()]"
132+
"[f for f in fs.get_transformation_functions()]"
133133
]
134134
},
135135
{
@@ -153,11 +153,11 @@
153153
"source": [
154154
"features_category = ['gender', 'age_cat', 'blood_gp', 'underlying_disease', 'gestation', 'prior_transplant', 'if_transplanted']\n",
155155
"\n",
156-
"transformation_functions_category = {\n",
157-
" feature_name: label_encoder\n",
156+
"transformation_functions_category = [\n",
157+
" label_encoder(feature_name)\n",
158158
" for feature_name\n",
159159
" in features_category\n",
160-
"}"
160+
"]"
161161
]
162162
},
163163
{
@@ -171,11 +171,11 @@
171171
" 'age_at_list_registration', 'dialysis_duration', 'number_prior_transplant', 'cpra', 'hla_a1', 'hla_a2', 'hla_b1', 'hla_b2', 'hla_dr1', 'hla_dr2',\n",
172172
"]\n",
173173
"\n",
174-
"transformation_functions_numerical = {\n",
175-
" feature_name: standard_scaler\n",
174+
"transformation_functions_numerical = [\n",
175+
" standard_scaler(feature_name)\n",
176176
" for feature_name\n",
177177
" in features_numerical\n",
178-
"}"
178+
"]"
179179
]
180180
},
181181
{
@@ -185,8 +185,8 @@
185185
"metadata": {},
186186
"outputs": [],
187187
"source": [
188-
"# Join transformation_functions_category and transformation_functions_numerical dictionaries into one\n",
189-
"transformation_functions = transformation_functions_category | transformation_functions_numerical"
188+
"# Join transformation_functions_category and transformation_functions_numerical lists into one\n",
189+
"transformation_functions = transformation_functions_category + transformation_functions_numerical"
190190
]
191191
},
192192
{

advanced_tutorials/on_demand_feature/notebooks/3_feature_view_td_modelling.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@
9999
"label_encoder = fs.get_transformation_function(name=\"label_encoder\")\n",
100100
"\n",
101101
"# Map features to transformation functions.\n",
102-
"transformation_functions = {\n",
103-
" \"ocean_proximity\": label_encoder,\n",
104-
"}"
102+
"transformation_functions = [\n",
103+
" label_encoder(\"ocean_proximity\")\n",
104+
"]"
105105
]
106106
},
107107
{

0 commit comments

Comments
 (0)