Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

docs: add snippet for predicting classifications using a boosted tree model #1156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions 31 samples/snippets/classification_boosted_tree_model_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_boosted_tree_model(random_model_id: str) -> None:
replace=True,
)
# [END bigquery_dataframes_bqml_boosted_tree_create]
# [START bigquery_dataframes_bqml_boosted_tree_explain]
# [START bigquery_dataframes_bqml_boosted_tree_evaluate]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best not to rename these, though in this case it should be OK since we haven't added the samples to cloud.google.com/bigquery/docs yet

# Select model you'll use for predictions. `read_gbq_model` loads model
# data from BigQuery, but you could also use the `tree_model` object
# from the previous step.
Expand All @@ -82,8 +82,33 @@ def test_boosted_tree_model(random_model_id: str) -> None:
# Output:
# precision recall accuracy f1_score log_loss roc_auc
# 0 0.671924 0.578804 0.839429 0.621897 0.344054 0.887335
# [END bigquery_dataframes_bqml_boosted_tree_explain]
# [END bigquery_dataframes_bqml_boosted_tree_evaluate]
# [START bigquery_dataframes_bqml_boosted_tree_predict]
# Select model you'll use for predictions. `read_gbq_model` loads model
# data from BigQuery, but you could also use the `tree_model` object
# from previous steps.
tree_model = bpd.read_gbq_model(
your_model_id, # For example: "your-project.bqml_tutorial.tree_model"
)

# input_data is defined in an earlier step.
prediction_data = input_data[input_data["dataframe"] == "prediction"]

predictions = tree_model.predict(prediction_data)
predictions.peek()
# Output:
# predicted_income_bracket predicted_income_bracket_probs.label predicted_income_bracket_probs.prob
# <=50K >50K 0.05183430016040802
# <50K 0.94816571474075317
# <=50K >50K 0.00365859130397439
# <50K 0.99634140729904175
# <=50K >50K 0.037775970995426178
# <50K 0.96222406625747681
# [END bigquery_dataframes_bqml_boosted_tree_predict]
assert input_data is not None
assert training_data is not None
assert tree_model is not None
assert evaluation_data is not None
assert score is not None
assert input_data is not None
assert prediction_data is not None
assert predictions is not None
Morty Proxy This is a proxified and sanitized view of the page, visit original site.