Skip to content

docs: add snippet for Linear Regression tutorial Predict Outcomes section #1101

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 17 commits into from
Oct 30, 2024
Merged
Changes from 7 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
20 changes: 19 additions & 1 deletion samples/snippets/linear_regression_tutorial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,27 @@ def test_linear_regression(random_model_id: str) -> None:
# Expected output results:
# index mean_absolute_error mean_squared_error mean_squared_log_error median_absolute_error r2_score explained_variance
# 0 227.012237 81838.159892 0.00507 173.080816 0.872377 0.872377
# 1 rows x columns
# 1 rows x 6 columns
# [END bigquery_dataframes_bqml_linear_evaluate]
# [START bigquery_dataframes_bqml_linear_predict]
# Select the model you'll use for predictions. `read_gbq_model` loads
# model data from BigQuery, but you could also use the `model` object
# object from previous steps.
model = bpd.read_gbq_model(
your_model_id,
# For example: "bqml_tutorial.penguins_model",
)

# Use 'contains' function to filter by island containing the string
# "Biscoe".
biscoe_data = model.loc[model["island"].str.contains("Biscoe")]

result = model.predict(biscoe_data)

# Expected output results:
# [END bigquery_dataframes_bqml_linear_predict]
assert feature_columns is not None
assert label_columns is not None
assert model is not None
assert score is not None
assert result is not None