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 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 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
27 changes: 26 additions & 1 deletion 27 samples/snippets/linear_regression_tutorial_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,34 @@ 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",
)

# Load data from BigQuery
bq_df = bpd.read_gbq("bigquery-public-data.ml_datasets.penguins")

# Use 'contains' function to filter by island containing the string
# "Biscoe".
tswast marked this conversation as resolved.
Show resolved Hide resolved
biscoe_data = bq_df.loc[bq_df["island"].str.contains("Biscoe")]

result = model.predict(biscoe_data)

# Expected output results:
rey-esp marked this conversation as resolved.
Show resolved Hide resolved
# predicted_body_mass_g species island culmen_length_mm culmen_depth_mm body_mass_g flipper_length_mm sex
# 23 4681.782896 Gentoo penguin (Pygoscelis papua) Biscoe <NA> <NA> <NA> <NA> <NA>
# 332 4740.7907 Gentoo penguin (Pygoscelis papua) Biscoe 46.2 14.4 214.0 4650.0 <NA>
# 160 4731.310452 Gentoo penguin (Pygoscelis papua) Biscoe 44.5 14.3 216.0 4100.0 <NA>
# [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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.