Skip to content

Commit a120bae

Browse files
authored
docs: add ml tutorial for Evaluate the model (#1038)
* add ml tutorial for Evaluate the model * remove alternative * remove alternative snippet * update description * avoid contractions * fix comment description * add expected results
1 parent 06cec00 commit a120bae

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

samples/snippets/linear_regression_tutorial_test.py

+18
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ def test_linear_regression(random_model_id: str) -> None:
3737
replace=True,
3838
)
3939
# [END bigquery_dataframes_bqml_linear_regression]
40+
# [START bigquery_dataframes_bqml_linear_evaluate]
41+
import bigframes.pandas as bpd
42+
43+
# Select the model you will be evaluating. `read_gbq_model` loads model data from
44+
# BigQuery, but you could also use the `model` object from the previous steps.
45+
model = bpd.read_gbq_model(
46+
your_model_id, # For example: "bqml_tutorial.penguins_model"
47+
)
48+
49+
# Score the model with input data defined in an earlier step to compare
50+
# model predictions on feature_columns to true labels in label_columns.
51+
score = model.score(feature_columns, label_columns)
52+
# Expected output results:
53+
# index mean_absolute_error mean_squared_error mean_squared_log_error median_absolute_error r2_score explained_variance
54+
# 0 227.012237 81838.159892 0.00507 173.080816 0.872377 0.872377
55+
# 1 rows x columns
56+
# [END bigquery_dataframes_bqml_linear_evaluate]
4057
assert feature_columns is not None
4158
assert label_columns is not None
4259
assert model is not None
60+
assert score is not None

0 commit comments

Comments
 (0)