GoogleCloudPlatform / GoogleCloudPlatform/training-data-analyst

Question: `preprocess_xgboost`

Open
#2,303 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
8.6k
Forks
6.1k
Avg merge
4h 44m
Merged PRs (30d)
2

Description

I have a question about [BQML notebook](https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/quests/vertex-ai/vertex-bqml/lab_exercise.ipynb).
In the double for loop at the function `preprocess_xgboost`, `instance_list` seems to be overwriten. Is it correct?(`instance_list = list(instance.values()) `should be aligned with `transformed_instances.append(instance_list)`?)

```
def preprocess_xgboost(instances, cat_feature_list, feature_encoders):
"""Transform instances to numerical values for inference.
Args:
instances (list[dict]): A list of feature dictionaries with the format feature: value.
cat_feature_list (list): A list of string feature names.
feature_encoders (dict): A dictionary with the format feature: feature_encoder.
Returns:
transformed_instances (list[list]): A list of lists containing numerical feature values needed
for Vertex XGBoost inference.
"""
transformed_instances = []

for instance in instances:
for feature in cat_feature_list:
feature_int = feature_encoders[feature].transform([[instance[feature]]]).item()
instance[feature] = feature_int
instance_list = list(instance.values())
transformed_instances.append(instance_list)

return transformed_instances
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.